MCPcopy
hub / github.com/btcsuite/btcd / removeOpcodeByData

Function removeOpcodeByData

txscript/script.go:258–284  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

256// does not accept a script version, the results are undefined for other script
257// versions.
258func 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
286func removeOpcodeCanonical(t *ScriptTokenizer, script, dataToRemove []byte,
287 prevOffset int32, result []byte) ([]byte, int32, bool) {

Callers 3

VerifyMethod · 0.85
opcodeCheckMultiSigFunction · 0.85
TestRemoveOpcodeByDataFunction · 0.85

Calls 3

MakeScriptTokenizerFunction · 0.85
removeOpcodeCanonicalFunction · 0.85
NextMethod · 0.65

Tested by 1

TestRemoveOpcodeByDataFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…