Minor cleanup.

This commit fixes a couple of comments and cleans up a couple of things
golint complained about.
This commit is contained in:
Dave Collins 2013-11-07 06:21:44 -06:00
parent 6f61e0acc2
commit dd41f7e91a
3 changed files with 13 additions and 11 deletions

View file

@ -140,7 +140,7 @@ func readElements(r io.Reader, elements ...interface{}) error {
func writeElement(w io.Writer, element interface{}) error { func writeElement(w io.Writer, element interface{}) error {
var scratch [8]byte 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. // type assertions first.
switch e := element.(type) { switch e := element.(type) {
case int32: case int32:
@ -238,6 +238,8 @@ func writeElement(w io.Writer, element interface{}) error {
return nil return nil
} }
// Fall back to the slower binary.Write if a fast path was not available
// above.
return binary.Write(w, binary.LittleEndian, element) return binary.Write(w, binary.LittleEndian, element)
} }

View file

@ -144,7 +144,7 @@ func (msg *MsgTx) AddTxOut(to *TxOut) {
} }
// TxSha generates the ShaHash name for the transaction. // 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. // Encode the transaction and calculate double sha256 on the result.
// Ignore the error returns since the only way the encode could fail // 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 // 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. // regardless of input.
var buf bytes.Buffer var buf bytes.Buffer
var sha ShaHash var sha ShaHash
_ = tx.Serialize(&buf) _ = msg.Serialize(&buf)
_ = sha.SetBytes(DoubleSha256(buf.Bytes())) _ = sha.SetBytes(DoubleSha256(buf.Bytes()))
// Even though this function can't currently fail, it still returns // 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 // Copy creates a deep copy of a transaction so that the original does not get
// modified when the copy is manipulated. // 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 // Create new tx and start by copying primitive values and making space
// for the transaction inputs and outputs. // for the transaction inputs and outputs.
newTx := MsgTx{ newTx := MsgTx{
Version: tx.Version, Version: msg.Version,
TxIn: make([]*TxIn, 0, len(tx.TxIn)), TxIn: make([]*TxIn, 0, len(msg.TxIn)),
TxOut: make([]*TxOut, 0, len(tx.TxOut)), TxOut: make([]*TxOut, 0, len(msg.TxOut)),
LockTime: tx.LockTime, LockTime: msg.LockTime,
} }
// Deep copy the old TxIn data. // Deep copy the old TxIn data.
for _, oldTxIn := range tx.TxIn { for _, oldTxIn := range msg.TxIn {
// Deep copy the old previous outpoint. // Deep copy the old previous outpoint.
oldOutPoint := oldTxIn.PreviousOutpoint oldOutPoint := oldTxIn.PreviousOutpoint
newOutPoint := OutPoint{} newOutPoint := OutPoint{}
@ -202,7 +202,7 @@ func (tx *MsgTx) Copy() *MsgTx {
} }
// Deep copy the old TxOut data. // Deep copy the old TxOut data.
for _, oldTxOut := range tx.TxOut { for _, oldTxOut := range msg.TxOut {
// Deep copy the old PkScript // Deep copy the old PkScript
var newScript []byte var newScript []byte
oldScript := oldTxOut.PkScript oldScript := oldTxOut.PkScript

View file

@ -18,7 +18,7 @@ const MaxHashStringSize = HashSize * 2
// ErrHashStrSize describes an error that indicates the caller specified a hash // ErrHashStrSize describes an error that indicates the caller specified a hash
// string that has too many characters. // 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 // ShaHash is used in several of the bitcoin messages and common structures. It
// typically represents the double sha256 of data. // typically represents the double sha256 of data.