removeOpcodeByData will return the script minus any opcodes that perform a canonical push of data that contains the passed data to remove. This function assumes it is provided a version 0 script as any future version of script should avoid this functionality since it is unnecessary due to the signa
(script []byte, dataToRemove []byte)
| 256 | // does not accept a script version, the results are undefined for other script |
| 257 | // versions. |
| 258 | func removeOpcodeByData(script []byte, dataToRemove []byte) ([]byte, bool) { |
| 259 | // Avoid work when possible. |
| 260 | if len(script) == 0 || len(dataToRemove) == 0 { |
| 261 | return script, false |
| 262 | } |
| 263 | |
| 264 | // Parse through the script looking for a canonical data push that contains |
| 265 | // the data to remove. |
| 266 | const scriptVersion = 0 |
| 267 | var result []byte |
| 268 | var prevOffset int32 |
| 269 | var match bool |
| 270 | tokenizer := MakeScriptTokenizer(scriptVersion, script) |
| 271 | for tokenizer.Next() { |
| 272 | var found bool |
| 273 | result, prevOffset, found = removeOpcodeCanonical( |
| 274 | &tokenizer, script, dataToRemove, prevOffset, result, |
| 275 | ) |
| 276 | if found { |
| 277 | match = true |
| 278 | } |
| 279 | } |
| 280 | if result == nil { |
| 281 | result = script |
| 282 | } |
| 283 | return result, match |
| 284 | } |
| 285 | |
| 286 | func removeOpcodeCanonical(t *ScriptTokenizer, script, dataToRemove []byte, |
| 287 | prevOffset int32, result []byte) ([]byte, int32, bool) { |
searching dependent graphs…