diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 96e9f80b6aac3..b6bf65bd059df 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -222,6 +222,16 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { return receipts } +// GetLogsByHash retrieves the logs from all receipts for all transactions in a given block. +func (bc *BlockChain) GetLogsByHash(hash common.Hash) [][]*types.Log { + receipts := bc.GetReceiptsByHash(hash) + logs := make([][]*types.Log, len(receipts)) + for i, receipt := range receipts { + logs[i] = receipt.Logs + } + return logs +} + // GetUnclesInChain retrieves all the uncles from a given block backwards until // a specific distance is reached. func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header { diff --git a/eth/api_backend.go b/eth/api_backend.go index 1d8ba8ea5cae0..b30d8846fb8ad 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -208,11 +208,8 @@ func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*typ if number == nil { return nil, fmt.Errorf("failed to get block number for hash %#x", hash) } - logs := rawdb.ReadLogs(db, hash, *number, b.eth.blockchain.Config()) - if logs == nil { - return nil, fmt.Errorf("failed to get logs for block #%d (0x%s)", *number, hash.TerminalString()) - } - return logs, nil + + return b.eth.blockchain.GetLogsByHash(hash), nil } func (b *EthAPIBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int {