Skip to content

Commit

Permalink
aligning the tests to this new concept
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Kellenschwiler <[email protected]>
  • Loading branch information
sirdeggen committed Sep 7, 2023
1 parent e64249b commit 558d9b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bscript/interpreter/opcodeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,23 @@ func (p *DefaultOpcodeParser) Parse(s *bscript.Script) (ParsedScript, error) {
// This must be the final evaluated opcode, everything after is ignored.
if conditionalBlock == 0 {
parsedOps = append(parsedOps, parsedOp)
// we add the last data as unformatted blob so that subScript can be reconstructed
// we add any remaining data as an unformatted blob so that subScript can be reconstructed
// but only if there is more length to this script. If it ends in OpReturn then stop there.
totalLen := len(script)
if (i + 1) > totalLen {
return parsedOps, nil
}
if (i + 2) > totalLen {
// we have a single byte of data
parsedOps = append(parsedOps, ParsedOpcode{op: opcode{
name: "Unformatted Data",
val: script[i+1],
length: 1,
}})
return parsedOps, nil
}
parsedOps = append(parsedOps, ParsedOpcode{op: opcode{
name: "Unformatteded Data",
name: "Unformatted Data",
val: script[i+1],
length: len(script[i+1:]),
}, Data: script[i+2:]})
Expand Down
8 changes: 8 additions & 0 deletions bscript/interpreter/opcodeparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func TestParse(t *testing.T) {
},
Data: nil,
},
ParsedOpcode{
op: opcode{
val: 0,
name: "Unformatted Data",
length: 3,
},
Data: []byte{36, 220},
},
},
},
}
Expand Down

0 comments on commit 558d9b6

Please sign in to comment.