wire: Remove errs from BlockHeader/MsgBlock/MsgTx.

This commit removes the error returns from the BlockHeader.BlockSha,
MsgBlock.BlockSha, and MsgTx.TxSha functions since they can never fail and
end up causing a lot of unneeded error checking throughout the code base.

It also updates all call sites for the change.
This commit is contained in:
Dave Collins 2015-04-17 01:09:21 -05:00
parent 88fd338420
commit a4a52ae24f
18 changed files with 36 additions and 115 deletions

View file

@ -91,7 +91,7 @@ endtest:
t.Errorf("referenced tx not found %v ", origintxsha)
}
}
txshaname, _ := tx.TxSha()
txshaname := tx.TxSha()
txlookupList = append(txlookupList, &txshaname)
txOutList = append(txOutList, &txshaname)
}

View file

@ -367,7 +367,7 @@ func testBackout(t *testing.T) {
block := testDb.blocks[119]
mblock := block.MsgBlock()
txsha, err := mblock.Transactions[0].TxSha()
txsha := mblock.Transactions[0].TxSha()
exists, err := testDb.db.ExistsTxSha(&txsha)
if err != nil {
t.Errorf("ExistsTxSha: unexpected error %v ", err)

View file

@ -482,7 +482,7 @@ func (db *LevelDb) FetchTxsForAddr(addr btcutil.Address, skip int,
continue
}
txSha, _ := tx.TxSha()
txSha := tx.TxSha()
txReply := &database.TxListReply{Sha: &txSha, Tx: tx,
BlkSha: blkSha, Height: blkHeight, TxSpent: []bool{}, Err: err}

View file

@ -184,7 +184,7 @@ func (db *MemDb) DropAfterBlockBySha(sha *wire.ShaHash) error {
transactions := db.blocks[i].Transactions
for j := len(transactions) - 1; j >= 0; j-- {
tx := transactions[j]
txHash, _ := tx.TxSha()
txHash := tx.TxSha()
db.removeTx(tx, &txHash)
}
@ -291,11 +291,7 @@ func (db *MemDb) FetchBlockShaByHeight(height int64) (*wire.ShaHash, error) {
}
msgBlock := db.blocks[height]
blockHash, err := msgBlock.BlockSha()
if err != nil {
return nil, err
}
blockHash := msgBlock.BlockSha()
return &blockHash, nil
}
@ -337,10 +333,7 @@ func (db *MemDb) FetchHeightRange(startHeight, endHeight int64) ([]wire.ShaHash,
}
msgBlock := db.blocks[i]
blockHash, err := msgBlock.BlockSha()
if err != nil {
return nil, err
}
blockHash := msgBlock.BlockSha()
hashList = append(hashList, blockHash)
}
@ -390,10 +383,7 @@ func (db *MemDb) FetchTxBySha(txHash *wire.ShaHash) ([]*database.TxListReply, er
replyList := make([]*database.TxListReply, len(txns))
for i, txD := range txns {
msgBlock := db.blocks[txD.blockHeight]
blockSha, err := msgBlock.BlockSha()
if err != nil {
return nil, err
}
blockSha := msgBlock.BlockSha()
spentBuf := make([]bool, len(txD.spentBuf))
copy(spentBuf, txD.spentBuf)
@ -455,11 +445,7 @@ func (db *MemDb) fetchTxByShaList(txShaList []*wire.ShaHash, includeSpent bool)
// the reply error appropriately and go to the next
// requested transaction if anything goes wrong.
msgBlock := db.blocks[txD.blockHeight]
blockSha, err := msgBlock.BlockSha()
if err != nil {
reply.Err = err
continue
}
blockSha := msgBlock.BlockSha()
// Make a copy of the spent buf to return so the caller
// can't accidentally modify it.
@ -685,11 +671,7 @@ func (db *MemDb) NewestSha() (*wire.ShaHash, int64, error) {
return &zeroHash, -1, nil
}
blockSha, err := db.blocks[numBlocks-1].BlockSha()
if err != nil {
return nil, -1, err
}
blockSha := db.blocks[numBlocks-1].BlockSha()
return &blockSha, int64(numBlocks - 1), nil
}

View file

@ -55,10 +55,7 @@ func TestClosed(t *testing.T) {
}
genesisCoinbaseTx := chaincfg.MainNetParams.GenesisBlock.Transactions[0]
coinbaseHash, err := genesisCoinbaseTx.TxSha()
if err != nil {
t.Errorf("TxSha: unexpected error %v", err)
}
coinbaseHash := genesisCoinbaseTx.TxSha()
if _, err := db.ExistsTxSha(&coinbaseHash); err != memdb.ErrDbClosed {
t.Errorf("ExistsTxSha: unexpected error %v", err)
}