reth_storage_api/
header.rsuse alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockHash, BlockNumber, U256};
use reth_primitives_traits::{BlockHeader, SealedHeader};
use reth_storage_errors::provider::ProviderResult;
use std::ops::RangeBounds;
pub type ProviderHeader<P> = <P as HeaderProvider>::Header;
#[auto_impl::auto_impl(&, Arc)]
pub trait HeaderProvider: Send + Sync {
type Header: BlockHeader;
fn is_known(&self, block_hash: &BlockHash) -> ProviderResult<bool> {
self.header(block_hash).map(|header| header.is_some())
}
fn header(&self, block_hash: &BlockHash) -> ProviderResult<Option<Self::Header>>;
fn sealed_header_by_hash(
&self,
block_hash: BlockHash,
) -> ProviderResult<Option<SealedHeader<Self::Header>>> {
Ok(self.header(&block_hash)?.map(|header| SealedHeader::new(header, block_hash)))
}
fn header_by_number(&self, num: u64) -> ProviderResult<Option<Self::Header>>;
fn header_by_hash_or_number(
&self,
hash_or_num: BlockHashOrNumber,
) -> ProviderResult<Option<Self::Header>> {
match hash_or_num {
BlockHashOrNumber::Hash(hash) => self.header(&hash),
BlockHashOrNumber::Number(num) => self.header_by_number(num),
}
}
fn header_td(&self, hash: &BlockHash) -> ProviderResult<Option<U256>>;
fn header_td_by_number(&self, number: BlockNumber) -> ProviderResult<Option<U256>>;
fn headers_range(
&self,
range: impl RangeBounds<BlockNumber>,
) -> ProviderResult<Vec<Self::Header>>;
fn sealed_header(
&self,
number: BlockNumber,
) -> ProviderResult<Option<SealedHeader<Self::Header>>>;
fn sealed_headers_range(
&self,
range: impl RangeBounds<BlockNumber>,
) -> ProviderResult<Vec<SealedHeader<Self::Header>>> {
self.sealed_headers_while(range, |_| true)
}
fn sealed_headers_while(
&self,
range: impl RangeBounds<BlockNumber>,
predicate: impl FnMut(&SealedHeader<Self::Header>) -> bool,
) -> ProviderResult<Vec<SealedHeader<Self::Header>>>;
}