good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit d7e0122b authored by Igor Mandrigin's avatar Igor Mandrigin Committed by GitHub
Browse files

`GetRecepts`: Read receipts from the DB. (#453)

parent 339316de
No related branches found
No related tags found
No related merge requests found
......@@ -182,26 +182,49 @@ 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 {
block := rawdb.ReadBlock(b.eth.chainDb, hash, *number)
dbstate := state.NewDbState(b.eth.chainDb, *number-1)
statedb := state.New(dbstate)
header := block.Header()
var receipts types.Receipts
var usedGas = new(uint64)
var gp = new(core.GasPool).AddGas(block.GasLimit())
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)
number := rawdb.ReadHeaderNumber(b.eth.chainDb, hash)
if number == nil {
return nil, nil
}
block := rawdb.ReadBlock(b.eth.chainDb, hash, *number)
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
var usedGas = new(uint64)
var gp = new(core.GasPool).AddGas(block.GasLimit())
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
}
return receipts, nil
receipts = append(receipts, receipt)
}
return nil, nil
return receipts, 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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment