feat: extend BlockProvider with default util functions (#1447)

This commit is contained in:
Matthias Seitz
2023-02-18 11:29:18 +01:00
committed by GitHub
parent b21f24c7cc
commit 1a31a21d31

View File

@ -1,6 +1,9 @@
use crate::{BlockIdProvider, HeaderProvider, TransactionsProvider};
use reth_interfaces::Result;
use reth_primitives::{rpc::BlockId, Block};
use reth_primitives::{
rpc::{BlockId, BlockNumber},
Block, H256,
};
/// Api trait for fetching `Block` related data.
#[auto_impl::auto_impl(&, Arc)]
@ -9,4 +12,20 @@ pub trait BlockProvider:
{
/// Returns the block. Returns `None` if block is not found.
fn block(&self, id: BlockId) -> Result<Option<Block>>;
/// Returns the block. Returns `None` if block is not found.
fn block_by_hash(&self, hash: H256) -> Result<Option<Block>> {
// TODO: replace with ruint
self.block(BlockId::Hash(reth_primitives::rpc::H256::from(hash.0)))
}
/// Returns the block. Returns `None` if block is not found.
fn block_by_number_or_tag(&self, num: BlockNumber) -> Result<Option<Block>> {
self.block(BlockId::Number(num))
}
/// Returns the block. Returns `None` if block is not found.
fn block_by_number(&self, num: u64) -> Result<Option<Block>> {
self.block(BlockId::Number(BlockNumber::Number(num.into())))
}
}