This updates all code in the main package and subpackages to make use of
the new chainhash package since the old wire.ShaHash type and functions
have been removed in favor of the abstracted package.
Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.
The following is an overview of the changes:
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
- Block.Sha -> Hash
- Block.TxSha -> TxHash
- Tx.Sha -> Hash
- bloom.Filter.AddShaHash -> AddHash
- Rename all variables that included sha in their name to include hash
instead
- Add license headers to coinset package files
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
Currently, transaction hash caching is provided via Block directly, but a
transaction is not always part of a block and there are several cases
where only the transaction needs to be dealt with without wanting to pass
the entire block and transaction index around to be able to get at the
cached hash.
So, this commit adds a new type named Tx which is a wrapper that provides
easier and more efficient manipulation of raw wire protocol transactions.
It memoizes the hash for the transaction on its first access so subsequent
accesses don't have to repeat the relatively expensive hashing operations.
The idea is the callers can pass around pointers to these Tx types instead
of raw btcwire.MsgTx pointers.
For now, the Block API has not been changed, but the plan is to change it
to provide access to these wrapped transactions rather than having it do
the transaction hash caching directly.
This is only the first part of a series of changes working towards
optimizations noted in conformal/btcd#25.