mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: extend BlockProvider with default util functions (#1447)
This commit is contained in:
@ -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())))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user