MCPcopy Create free account
hub / github.com/btcsuite/btcd / removeOpcodeRaw

Function removeOpcodeRaw

txscript/script.go:187–213  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

185// does not accept a script version, the results are undefined for other script
186// versions.
187func 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

Callers 2

TestRemoveOpcodesFunction · 0.85
calcSignatureHashFunction · 0.85

Calls 4

MakeScriptTokenizerFunction · 0.85
OpcodeMethod · 0.80
ByteIndexMethod · 0.80
NextMethod · 0.65

Tested by 1

TestRemoveOpcodesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…