mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-25 07:07:45 +01:00
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) {
|
func DisasmString(buf []byte) (string, error) {
|
||||||
disbuf := ""
|
disbuf := ""
|
||||||
opcodes, err := parseScript(buf)
|
opcodes, err := parseScript(buf)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
for _, pop := range opcodes {
|
for _, pop := range opcodes {
|
||||||
disbuf += pop.print(true) + " "
|
disbuf += pop.print(true) + " "
|
||||||
}
|
}
|
||||||
if disbuf != "" {
|
if disbuf != "" {
|
||||||
disbuf = disbuf[:len(disbuf)-1]
|
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
|
// calcScriptHash will, given the a script and hashtype for the current
|
||||||
|
|
Loading…
Add table
Reference in a new issue