Skip to content

Commit

Permalink
Read locktime into locktime var rather than version (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordishs authored Oct 1, 2021
1 parent 4c13db4 commit 6d01c9e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NewTxFromReader(r io.Reader) (*Tx, error) {
}

locktime := make([]byte, 4)
if n, err := io.ReadFull(r, version); n != 4 || err != nil {
if n, err := io.ReadFull(r, locktime); n != 4 || err != nil {
return nil, err
}
t.LockTime = binary.LittleEndian.Uint32(locktime)
Expand Down
17 changes: 17 additions & 0 deletions tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,3 +1124,20 @@ func TestTx_HasOutputsWithAddress(t *testing.T) {
})
}
}

func TestTXLocktime(t *testing.T) {
txHex := "0200000001c62f5df294ab2d22184668b5589cbd4fd3f0882e547cd6affa449fdec385e85a010000006b483045022100bdd0d0843d04a0e2ffcca13d7ba2e283b93455bdf1f62a953943882a1844384902206e1c9050695d728eedec83289bafbd4f3a82603e1e5acfd589b6bcaca6777b1941210377a1922cf0d29ed2a26d4e8dc94486c2e1071f5c0f3efa44f05292be15165fbbfeffffff027039333c000000001976a91496f0222a34f8e7c0f909ac54493d724aabc0c70b88ace11d7218000000001976a914f65696c35c694cede991cf04781940dd27aff75088acfdc80a00"

tx, err := bt.NewTxFromString(txHex)
if err != nil {
t.Error(err)
}

expected := "e14192d41196f4f374ec03259700f82c266cd316fe5da998de541903bffc40b4"
txid := tx.GetTxID()

if txid != expected {
t.Errorf("Expected %q, got %q", expected, txid)
}

}

0 comments on commit 6d01c9e

Please sign in to comment.