laconicd-deprecated/rpc/backend/filters.go
Daniel Burckhardt 9f03ca713d
tests(rpc): add backend blocks tests (#1296)
* wip

* rename GetTendermintBlockByNumber to TendermintBlockByNumber

* rename GetTendermintBlockResultByNumber to TendermintBlockResultByNumber

* rename GetTendermintBlockByHash to TendermintBlockByHash

* rename BlockByNumber to EthBlockByNumber

* rename BlockByHash to EthBlockByHash

* rename GetBlockNumberByHash to BlockNumberFromTendermintByHash

* rename GetBlockNumber to BlockNumberFromTendermint

* rename GetEthereumMsgsFromTendermintBlock to EthMsgsFromTendermintBlock

* rename GetEthBlockFromTendermint to BlockFromTendermintBlock

* rename EthBlockFromTendermint to EthBlockFromTendermintBlock

* add TestEthBlockFromTendermintBlock with no transactions. Note that this endpoint is breaking when querying a block with transactions

* add block transaction count tests

* add TendermintBlockByHash test'

* add TestBlockNumberFromTendermint tests

* add HeaderByHash and HeaderByNumber tests

* add EthBlockFromTendermintBlock test

* add TestEthBlockByNumber tests

* Specificy that the endpoints are getting Etherum transactions in comments

* Refactor shared logic into GetBlockTransactionCount

* rename BlockFromTendermintBlock to RPCBlockFromTendermintBlock

* add CHangelog
2022-09-05 16:07:56 +02:00

38 lines
1.1 KiB
Go

package backend
import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
)
// GetLogs returns all the logs from all the ethereum transactions in a block.
func (b *Backend) GetLogs(hash common.Hash) ([][]*ethtypes.Log, error) {
resBlock, err := b.TendermintBlockByHash(hash)
if err != nil {
return nil, err
}
if resBlock == nil {
return nil, errors.Errorf("block not found for hash %s", hash)
}
return b.GetLogsByHeight(&resBlock.Block.Header.Height)
}
// GetLogsByHeight returns all the logs from all the ethereum transactions in a block.
func (b *Backend) GetLogsByHeight(height *int64) ([][]*ethtypes.Log, error) {
// NOTE: we query the state in case the tx result logs are not persisted after an upgrade.
blockRes, err := b.TendermintBlockResultByNumber(height)
if err != nil {
return nil, err
}
return GetLogsFromBlockResults(blockRes)
}
// BloomStatus returns the BloomBitsBlocks and the number of processed sections maintained
// by the chain indexer.
func (b *Backend) BloomStatus() (uint64, uint64) {
return 4096, 0
}