Skip to content

Commit

Permalink
Merge pull request #31 from libsv/fix/p2pkhbytelen
Browse files Browse the repository at this point in the history
  • Loading branch information
jadwahab authored Jul 26, 2021
2 parents 4445010 + 1ead0f5 commit 78c9d18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bscript/bip276_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestDecodeBIP276(t *testing.T) {
assert.Equal(t, `"bitcoin-script"`, fmt.Sprintf("%q", prefix))
assert.Equal(t, 1, network)
assert.Equal(t, 1, version)
assert.Equal(t, "fake script", fmt.Sprintf("%s", data))
assert.Equal(t, "fake script", string(data))
})

t.Run("invalid decode", func(t *testing.T) {
Expand All @@ -123,6 +123,6 @@ func TestDecodeBIP276(t *testing.T) {
assert.Equal(t, `"bitcoin-script"`, fmt.Sprintf("%q", prefix))
assert.Equal(t, 1, network)
assert.Equal(t, 1, version)
assert.Equal(t, "fake scrip", fmt.Sprintf("%s", data))
assert.Equal(t, "fake scrip", string(data))
})
}
4 changes: 2 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ func (tx *Tx) canAddChange(available uint64, standardFees *Fee) bool {
}

changeOutputFee := uint64(varIntUpper)

changeP2pkhByteLen := 8 + 25 // 8 bytes for satoshi value + 25 bytes for p2pkh script (e.g. 76a914cc...05388ac)
// 8 bytes for satoshi value +1 for varint length + 25 bytes for p2pkh script (e.g. 76a914cc...05388ac)
changeP2pkhByteLen := 8 + 1 + 25
changeOutputFee += uint64(changeP2pkhByteLen * standardFees.MiningFee.Satoshis / standardFees.MiningFee.Bytes)

// not enough change to add a whole change output so don't add anything and return
Expand Down

0 comments on commit 78c9d18

Please sign in to comment.