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:
Dave Collins 2014-01-03 18:47:00 -06:00
parent 814c920c96
commit eb4fc19b95

View file

@ -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