Modify DisasmString to return partial disassembly.
Rather than returning an empty string from DisasmString if a script fails to parse, return the disassembly up to the point of the failure along with [error] appended. The error is still returned in case the caller wants more information about the script parse failure.
This commit is contained in:
parent
814c920c96
commit
eb4fc19b95
1 changed files with 9 additions and 5 deletions
14
script.go
14
script.go
|
@ -693,20 +693,24 @@ func removeOpcodeByData(pkscript []parsedOpcode, data []byte) []parsedOpcode {
|
|||
|
||||
}
|
||||
|
||||
// DisasmString formats a disassembled script for one line printing.
|
||||
// DisasmString formats a disassembled script for one line printing. When the
|
||||
// script fails to parse, the returned string will contain the disassembled
|
||||
// script up to the point the failure occurred along with the string '[error]'
|
||||
// appended. In addition, the reason the script failed to parse is returned
|
||||
// if the caller wants more information about the failure.
|
||||
func DisasmString(buf []byte) (string, error) {
|
||||
disbuf := ""
|
||||
opcodes, err := parseScript(buf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, pop := range opcodes {
|
||||
disbuf += pop.print(true) + " "
|
||||
}
|
||||
if disbuf != "" {
|
||||
disbuf = disbuf[:len(disbuf)-1]
|
||||
}
|
||||
return disbuf, nil
|
||||
if err != nil {
|
||||
disbuf += "[error]"
|
||||
}
|
||||
return disbuf, err
|
||||
}
|
||||
|
||||
// calcScriptHash will, given the a script and hashtype for the current
|
||||
|
|
Loading…
Reference in a new issue