core, eth, les, light: scope receipt functionality a bit cleaner

This commit is contained in:
Péter Szilágyi
2019-04-15 12:36:27 +03:00
parent 6b0ddd141e
commit 7221cb1434
16 changed files with 250 additions and 287 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
)
@ -85,7 +86,8 @@ func ReadTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, com
// ReadReceipt retrieves a specific transaction receipt from the database, along with
// its added positional metadata.
func ReadReceipt(db ethdb.Reader, hash common.Hash) (*types.Receipt, common.Hash, uint64, uint64) {
func ReadReceipt(db ethdb.Reader, hash common.Hash, config *params.ChainConfig) (*types.Receipt, common.Hash, uint64, uint64) {
// Retrieve the context of the receipt based on the transaction hash
blockHash := ReadTxLookupEntry(db, hash)
if blockHash == (common.Hash{}) {
return nil, common.Hash{}, 0, 0
@ -94,7 +96,8 @@ func ReadReceipt(db ethdb.Reader, hash common.Hash) (*types.Receipt, common.Hash
if blockNumber == nil {
return nil, common.Hash{}, 0, 0
}
receipts := ReadReceipts(db, blockHash, *blockNumber)
// Read all the receipts from the block and return the one with the matching hash
receipts := ReadReceipts(db, blockHash, *blockNumber, config)
for receiptIndex, receipt := range receipts {
if receipt.TxHash == hash {
return receipt, blockHash, *blockNumber, uint64(receiptIndex)