Skip to content

Commit

Permalink
Optimise ToASM() func using string builder (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordishs authored Oct 29, 2021
1 parent 6d01c9e commit 4469110
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,22 @@ func (s *Script) ToASM() (string, error) {
parts, err := DecodeParts(*s)
// if err != nil, we will append [error] to the ASM script below (as done in the node).

var asmScript string
var asmScript strings.Builder

for _, p := range parts {
asmScript.WriteString(" ")
if len(p) == 1 {
asmScript = asmScript + " " + opCodeValues[p[0]]
asmScript.WriteString(opCodeValues[p[0]])
} else {
asmScript = asmScript + " " + hex.EncodeToString(p)
asmScript.WriteString(hex.EncodeToString(p))
}
}

if err != nil {
asmScript += " [error]"
asmScript.WriteString(" [error]")
}

return strings.TrimSpace(asmScript), nil
return strings.TrimSpace(asmScript.String()), nil
}

// IsP2PKH returns true if this is a pay to pubkey hash output script.
Expand Down

0 comments on commit 4469110

Please sign in to comment.