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 i
(script []byte)
| 155 | // does not accept a script version, the results are undefined for other script |
| 156 | // versions. |
| 157 | func DisasmString(script []byte) (string, error) { |
| 158 | const scriptVersion = 0 |
| 159 | |
| 160 | var disbuf strings.Builder |
| 161 | tokenizer := MakeScriptTokenizer(scriptVersion, script) |
| 162 | if tokenizer.Next() { |
| 163 | disasmOpcode(&disbuf, tokenizer.op, tokenizer.Data(), true) |
| 164 | } |
| 165 | for tokenizer.Next() { |
| 166 | disbuf.WriteByte(' ') |
| 167 | disasmOpcode(&disbuf, tokenizer.op, tokenizer.Data(), true) |
| 168 | } |
| 169 | if tokenizer.Err() != nil { |
| 170 | if tokenizer.ByteIndex() != 0 { |
| 171 | disbuf.WriteByte(' ') |
| 172 | } |
| 173 | disbuf.WriteString("[error]") |
| 174 | } |
| 175 | return disbuf.String(), tokenizer.Err() |
| 176 | } |
| 177 | |
| 178 | // removeOpcodeRaw will return the script after removing any opcodes that match |
| 179 | // `opcode`. If the opcode does not appear in script, the original script will |
searching dependent graphs…