From eb4fc19b95258863af88859a4ba2934d5199ca76 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 3 Jan 2014 18:47:00 -0600 Subject: [PATCH] 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. --- script.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/script.go b/script.go index 3288ca11..e46be23a 100644 --- a/script.go +++ b/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