removeOpcodeRaw will return the script after removing any opcodes that match `opcode`. If the opcode does not appear in script, the original script will be returned unmodified. Otherwise, a new script will be allocated to contain the filtered script. This method assumes that the script parses succes
(script []byte, opcode byte)
| 185 | // does not accept a script version, the results are undefined for other script |
| 186 | // versions. |
| 187 | func removeOpcodeRaw(script []byte, opcode byte) []byte { |
| 188 | // Avoid work when possible. |
| 189 | if len(script) == 0 { |
| 190 | return script |
| 191 | } |
| 192 | |
| 193 | const scriptVersion = 0 |
| 194 | var result []byte |
| 195 | var prevOffset int32 |
| 196 | |
| 197 | tokenizer := MakeScriptTokenizer(scriptVersion, script) |
| 198 | for tokenizer.Next() { |
| 199 | if tokenizer.Opcode() == opcode { |
| 200 | if result == nil { |
| 201 | result = make([]byte, 0, len(script)) |
| 202 | result = append(result, script[:prevOffset]...) |
| 203 | } |
| 204 | } else if result != nil { |
| 205 | result = append(result, script[prevOffset:tokenizer.ByteIndex()]...) |
| 206 | } |
| 207 | prevOffset = tokenizer.ByteIndex() |
| 208 | } |
| 209 | if result == nil { |
| 210 | return script |
| 211 | } |
| 212 | return result |
| 213 | } |
| 214 | |
| 215 | // isCanonicalPush returns true if the opcode is either not a push instruction |
| 216 | // or the data associated with the push instruction uses the smallest |
searching dependent graphs…