Skip to content

Commit

Permalink
Minor changes to address comments in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ordishs committed Nov 14, 2022
1 parent 548edc8 commit 649090f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (s *Script) ToASM() (string, error) {
// if err != nil, we will append [error] to the ASM script below (as done in the node).

data := false
if len(*s) > 1 && ((*s)[0] == 0x6a || ((*s)[0] == 0x00 && (*s)[1] == 0x6a)) {
if len(*s) > 1 && ((*s)[0] == OpRETURN || ((*s)[0] == OpFALSE && (*s)[1] == OpRETURN)) {
data = true
}

Expand Down
2 changes: 1 addition & 1 deletion bscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestScript_UnmarshalJSON(t *testing.T) {
}
}

func TestRunScriptExample1(t *testing.T) {
func TestScriptToAsm(t *testing.T) {
script, _ := hex.DecodeString("006a2231394878696756345179427633744870515663554551797131707a5a56646f4175744d7301e4b8bbe381aa54574954544552e381a8425356e381ae547765746368e381a7e381aee98195e381840a547765746368e381a7e381afe887aae58886e381aee69bb8e38184e3819fe38384e382a8e383bce38388e381afe4b880e795aae69c80e5889de381bee381a70ae38195e3818be381aee381bce381a3e381a6e38184e381a4e381a7e38282e7a2bae8aa8de58fafe883bde381a7e8aaade381bfe8bebce381bfe381a7e995b7e69982e996930ae5819ce6ada2e381afe38182e3828ae381bee3819be38293e380825954e383aae383b3e382afe381aee58b95e794bbe38292e8a696e881b4e38197e3819fe5a0b4e590880ae99fb3e6a5bde381afe382b9e382afe383ade383bce383abe38197e381a6e38282e98094e58887e3828ce3819ae881b4e38193e38188e3819fe381bee381be0ae38384e382a4e38383e382bfe383bce381afe69c80e5889de381aee383ace382b9e381bee381a7e8a18ce38191e381aae38184e381a7e38197e38287e380820a746578742f706c61696e04746578741f7477657463685f7477746578745f313634343834393439353138332e747874017c223150755161374b36324d694b43747373534c4b79316b683536575755374d74555235035345540b7477646174615f6a736f6e046e756c6c0375726c046e756c6c07636f6d6d656e74046e756c6c076d625f757365720439373038057265706c794035366462363536376363306230663539316265363561396135313731663533396635316334333165643837356464326136373431643733353061353539363762047479706504706f73740974696d657374616d70046e756c6c036170700674776574636807696e766f6963652461366637336133312d336334342d346164612d393937352d386537386261666661623765017c22313550636948473232534e4c514a584d6f53556157566937575371633768436676610d424954434f494e5f454344534122314c6970354b335671677743415662674d7842536547434d344355364e344e6b75744c58494b4b554a35765a7753336b4c456e353749356a36485a2b43325733393834314e543532334a4c374534387655706d6f57306b4677613767392b51703246434f4d42776a556a7a76454150624252784d496a746c6b476b3d")
s := bscript.Script(script)

Expand Down
12 changes: 10 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (tx *Tx) ReadFrom(r io.Reader) (int64, error) {
*tx = Tx{}
var bytesRead int64

// Define n64 and err here to avoid linter complaining about shadowing variables.
var n64 int64
var err error

Expand All @@ -118,9 +119,11 @@ func (tx *Tx) ReadFrom(r io.Reader) (int64, error) {
var outputCount VarInt
locktime := make([]byte, 4)

// ----------------------------------------------------------------------------------
// If the inputCount is 0, we may be parsing an incomplete transaction, or we may be
// both of these cases without needing to rewind (peek) the incoming stream of bytes.
// ----------------------------------------------------------------------------------
if inputCount == 0 {
// The next bytes are either 0xEF or a varint that specifies the number of outputs
// Read 1 more byte to see if this is in extended format...
n64, err = outputCount.ReadFrom(r)
bytesRead += n64
if err != nil {
Expand Down Expand Up @@ -149,6 +152,11 @@ func (tx *Tx) ReadFrom(r io.Reader) (int64, error) {
}
}
}
// ----------------------------------------------------------------------------------
// If we have not returned from the previous block, we will have detected a sane
// transaction and we will know if it is extended format or not.
// We can now proceed with reading the rest of the transaction.
// ----------------------------------------------------------------------------------

// create Inputs
for i := uint64(0); i < uint64(inputCount); i++ {
Expand Down

0 comments on commit 649090f

Please sign in to comment.