File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 44 "encoding/binary"
55 "encoding/hex"
66 "fmt"
7+ "slices"
78)
89
910type ScriptChunk struct {
@@ -232,10 +233,16 @@ func DecodeScriptHex(s string) ([]*ScriptChunk, error) {
232233 return DecodeScript (b )
233234}
234235
236+ type DecodeOptions int
237+
238+ const (
239+ DecodeOptionsParseOpReturn DecodeOptions = 0
240+ )
241+
235242// DecodeScript takes bytes and decodes the opcodes in it
236243// returning an array of opcode parts (which could be opcodes or data
237244// pushed to the stack).
238- func DecodeScript (b []byte ) ([]* ScriptChunk , error ) {
245+ func DecodeScript (b []byte , options ... DecodeOptions ) ([]* ScriptChunk , error ) {
239246 var ops []* ScriptChunk
240247 conditionalBlock := 0
241248 for len (b ) > 0 {
@@ -249,11 +256,11 @@ func DecodeScript(b []byte) ([]*ScriptChunk, error) {
249256 conditionalBlock --
250257 b = b [1 :]
251258 case OpRETURN :
252- if conditionalBlock == 0 {
259+ if (slices .Contains (options , DecodeOptionsParseOpReturn )) || conditionalBlock > 0 {
260+ b = b [1 :]
261+ } else {
253262 op .Data = b
254263 b = nil
255- } else {
256- b = b [1 :]
257264 }
258265 case OpPUSHDATA1 :
259266 if len (b ) < 2 {
You can’t perform that action at this time.
0 commit comments