diff --git a/bench_test.go b/bench_test.go index f17ac565..a144b932 100644 --- a/bench_test.go +++ b/bench_test.go @@ -140,3 +140,12 @@ func BenchmarkWriteOutPoint(b *testing.B) { btcwire.TstWriteOutPoint(ioutil.Discard, 0, 0, op) } } + +// BenchmarkWriteTxOut performs a benchmark on how long it takes to write +// a transaction output. +func BenchmarkWriteTxOut(b *testing.B) { + txOut := blockOne.Transactions[0].TxOut[0] + for i := 0; i < b.N; i++ { + btcwire.TstWriteTxOut(ioutil.Discard, 0, 0, txOut) + } +} diff --git a/internal_test.go b/internal_test.go index bae8181e..8e07775b 100644 --- a/internal_test.go +++ b/internal_test.go @@ -114,3 +114,9 @@ func TstReadOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) err func TstWriteOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error { return writeOutPoint(w, pver, version, op) } + +// TstWriteTxOut makes the internal writeTxOut function available to the test +// package. +func TstWriteTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error { + return writeTxOut(w, pver, version, to) +} diff --git a/msgtx.go b/msgtx.go index 891bb5da..cf75bead 100644 --- a/msgtx.go +++ b/msgtx.go @@ -339,7 +339,7 @@ func (msg *MsgTx) BtcEncode(w io.Writer, pver uint32) error { } for _, to := range msg.TxOut { - err = writeTxOut(w, pver, to) + err = writeTxOut(w, pver, msg.Version, to) if err != nil { return err } @@ -551,7 +551,7 @@ func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error { // writeTxOut encodes to into the bitcoin protocol encoding for a transaction // output (TxOut) to w. -func writeTxOut(w io.Writer, pver uint32, to *TxOut) error { +func writeTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error { err := writeElement(w, to.Value) if err != nil { return err