While here, remove the serializedTx field from Tx. This field was
originally intended to be used to cache the bytes of the serialized
transaction, but it was never used and can effectively leak memory if
the Tx was created with a call to NewTxFromBytes.
ok @davecgh
bytes.Reader is a little bit more efficient than a bytes.Buffer when
just reading, so in situations where only an io.Reader is needed (for
Block and Tx deserialization), switch to a bytes.Reader.
ok @davecgh
This commit removes the previously deprecated TxShas function from
btcutil.Block. The preferred method to access transaction hashes is via
the Sha function on each btcutil.Tx contained within the block.
For example, the following illustrates how convert the old TxShas approach
to the new method:
OLD:
for i, sha := range block.TxShas() {
// use sha
}
NEW:
for i, tx := range block.Transactions() {
// use tx.Sha()
}
This commit also updates the tests for the removed function.
This commit adds two new functions to the Block API for working with the
recently added Tx type from the Block.
These new functions are named Tx and Transactions. Tx returns a
transactions for the specified index as a Tx and also memoizes it so
subsequent calls are more efficient. Transactions returns a slice of all
transactions in the Block wrapped in a Tx.
This is part of the ongoing transaction hash optimization effort
noted in conformal/btcd#25.
This commit unfortunately changes the public API of Block which I
ordinarily don't like to do, but in this case, I felt it was necessary.
The blocks used throughout the database and elsewhere should be indepedent
of the protocol version which is used to encode the block to wire format.
Each block has its own Version field which should be the deciding factor
for the serialization and deserialization of blocks. In practice, they
are currently the same encoding, but that may not always be the case, and
it's important the blocks are stable depending on their own version
regardless of the protocol version.
This makes use of the new Serialize and Deserialize functions on MsgBlock
which are intended for long-term storage as opposed to wire encoding.