mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
GetRecepts
: Read receipts from the DB. (#453)
This commit is contained in:
parent
339316deb2
commit
d7e0122b1f
@ -182,9 +182,22 @@ func (b *EthAPIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockN
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
|
||||
if number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash); number != nil {
|
||||
number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash)
|
||||
if number == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
block := rawdb.ReadBlock(b.eth.chainDb, hash, *number)
|
||||
dbstate := state.NewDbState(b.eth.chainDb, *number-1)
|
||||
|
||||
if cached := b.tryGetReceiptsFromDb(block); cached != nil {
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
return b.getReceiptsByReApplyingTransactions(block, *number)
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) getReceiptsByReApplyingTransactions(block *types.Block, number uint64) (types.Receipts, error) {
|
||||
dbstate := state.NewDbState(b.eth.chainDb, number-1)
|
||||
statedb := state.New(dbstate)
|
||||
header := block.Header()
|
||||
var receipts types.Receipts
|
||||
@ -193,15 +206,25 @@ func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (type
|
||||
vmConfig := vm.Config{}
|
||||
for i, tx := range block.Transactions() {
|
||||
statedb.Prepare(tx.Hash(), block.Hash(), i)
|
||||
|
||||
receipt, err := core.ApplyTransaction(b.ChainConfig(), b.eth.blockchain, nil, gp, statedb, dbstate, header, tx, usedGas, vmConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
receipts = append(receipts, receipt)
|
||||
}
|
||||
|
||||
return receipts, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) tryGetReceiptsFromDb(block *types.Block) types.Receipts {
|
||||
return rawdb.ReadReceipts(
|
||||
b.eth.chainDb,
|
||||
block.Hash(),
|
||||
block.NumberU64(),
|
||||
b.eth.blockchain.Config(),
|
||||
)
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user