diff --git a/common.go b/common.go index 299b9f6f..db4da0ac 100644 --- a/common.go +++ b/common.go @@ -140,7 +140,7 @@ func readElements(r io.Reader, elements ...interface{}) error { func writeElement(w io.Writer, element interface{}) error { var scratch [8]byte - // Attempt to read the element based on the concrete type via fast + // Attempt to write the element based on the concrete type via fast // type assertions first. switch e := element.(type) { case int32: @@ -238,6 +238,8 @@ func writeElement(w io.Writer, element interface{}) error { return nil } + // Fall back to the slower binary.Write if a fast path was not available + // above. return binary.Write(w, binary.LittleEndian, element) } diff --git a/msgtx.go b/msgtx.go index 7e0ac38b..f4ae9af7 100644 --- a/msgtx.go +++ b/msgtx.go @@ -144,7 +144,7 @@ func (msg *MsgTx) AddTxOut(to *TxOut) { } // TxSha generates the ShaHash name for the transaction. -func (tx *MsgTx) TxSha() (ShaHash, error) { +func (msg *MsgTx) TxSha() (ShaHash, error) { // Encode the transaction and calculate double sha256 on the result. // Ignore the error returns since the only way the encode could fail // is being out of memory or due to nil pointers, both of which would @@ -153,7 +153,7 @@ func (tx *MsgTx) TxSha() (ShaHash, error) { // regardless of input. var buf bytes.Buffer var sha ShaHash - _ = tx.Serialize(&buf) + _ = msg.Serialize(&buf) _ = sha.SetBytes(DoubleSha256(buf.Bytes())) // Even though this function can't currently fail, it still returns @@ -164,18 +164,18 @@ func (tx *MsgTx) TxSha() (ShaHash, error) { // Copy creates a deep copy of a transaction so that the original does not get // modified when the copy is manipulated. -func (tx *MsgTx) Copy() *MsgTx { +func (msg *MsgTx) Copy() *MsgTx { // Create new tx and start by copying primitive values and making space // for the transaction inputs and outputs. newTx := MsgTx{ - Version: tx.Version, - TxIn: make([]*TxIn, 0, len(tx.TxIn)), - TxOut: make([]*TxOut, 0, len(tx.TxOut)), - LockTime: tx.LockTime, + Version: msg.Version, + TxIn: make([]*TxIn, 0, len(msg.TxIn)), + TxOut: make([]*TxOut, 0, len(msg.TxOut)), + LockTime: msg.LockTime, } // Deep copy the old TxIn data. - for _, oldTxIn := range tx.TxIn { + for _, oldTxIn := range msg.TxIn { // Deep copy the old previous outpoint. oldOutPoint := oldTxIn.PreviousOutpoint newOutPoint := OutPoint{} @@ -202,7 +202,7 @@ func (tx *MsgTx) Copy() *MsgTx { } // Deep copy the old TxOut data. - for _, oldTxOut := range tx.TxOut { + for _, oldTxOut := range msg.TxOut { // Deep copy the old PkScript var newScript []byte oldScript := oldTxOut.PkScript diff --git a/shahash.go b/shahash.go index a3966bbf..57ea2f74 100644 --- a/shahash.go +++ b/shahash.go @@ -18,7 +18,7 @@ const MaxHashStringSize = HashSize * 2 // ErrHashStrSize describes an error that indicates the caller specified a hash // string that has too many characters. -var ErrHashStrSize = fmt.Errorf("Max hash length is %v chars", MaxHashStringSize) +var ErrHashStrSize = fmt.Errorf("max hash length is %v chars", MaxHashStringSize) // ShaHash is used in several of the bitcoin messages and common structures. It // typically represents the double sha256 of data.