reth::providers

Trait BlockReader

pub trait BlockReader:
    BlockNumReader
    + HeaderProvider
    + BlockBodyIndicesProvider
    + TransactionsProvider
    + ReceiptProvider
    + WithdrawalsProvider
    + OmmersProvider
    + Send
    + Sync {
    type Block: Block<Header = Self::Header>
       where <Self::Block as Block>::Body: BlockBody<Transaction = Self::Transaction>;

    // Required methods
    fn find_block_by_hash(
        &self,
        hash: FixedBytes<32>,
        source: BlockSource,
    ) -> Result<Option<Self::Block>, ProviderError>;
    fn block(
        &self,
        id: HashOrNumber,
    ) -> Result<Option<Self::Block>, ProviderError>;
    fn pending_block(
        &self,
    ) -> Result<Option<SealedBlock<<Self::Block as Block>::Header, <Self::Block as Block>::Body>>, ProviderError>;
    fn pending_block_with_senders(
        &self,
    ) -> Result<Option<SealedBlockWithSenders<Self::Block>>, ProviderError>;
    fn pending_block_and_receipts(
        &self,
    ) -> Result<Option<(SealedBlock<<Self::Block as Block>::Header, <Self::Block as Block>::Body>, Vec<Self::Receipt>)>, ProviderError>;
    fn block_with_senders(
        &self,
        id: HashOrNumber,
        transaction_kind: TransactionVariant,
    ) -> Result<Option<BlockWithSenders<Self::Block>>, ProviderError>;
    fn sealed_block_with_senders(
        &self,
        id: HashOrNumber,
        transaction_kind: TransactionVariant,
    ) -> Result<Option<SealedBlockWithSenders<Self::Block>>, ProviderError>;
    fn block_range(
        &self,
        range: RangeInclusive<u64>,
    ) -> Result<Vec<Self::Block>, ProviderError>;
    fn block_with_senders_range(
        &self,
        range: RangeInclusive<u64>,
    ) -> Result<Vec<BlockWithSenders<Self::Block>>, ProviderError>;
    fn sealed_block_with_senders_range(
        &self,
        range: RangeInclusive<u64>,
    ) -> Result<Vec<SealedBlockWithSenders<Self::Block>>, ProviderError>;

    // Provided methods
    fn block_by_hash(
        &self,
        hash: FixedBytes<32>,
    ) -> Result<Option<Self::Block>, ProviderError> { ... }
    fn block_by_number(
        &self,
        num: u64,
    ) -> Result<Option<Self::Block>, ProviderError> { ... }
}
Expand description

Api trait for fetching Block related data.

If not requested otherwise, implementers of this trait should prioritize fetching blocks from the database.

Required Associated Types§

type Block: Block<Header = Self::Header> where <Self::Block as Block>::Body: BlockBody<Transaction = Self::Transaction>

The block type this provider reads.

Required Methods§

fn find_block_by_hash( &self, hash: FixedBytes<32>, source: BlockSource, ) -> Result<Option<Self::Block>, ProviderError>

Tries to find in the given block source.

Note: this only operates on the hash because the number might be ambiguous.

Returns None if block is not found.

fn block(&self, id: HashOrNumber) -> Result<Option<Self::Block>, ProviderError>

Returns the block with given id from the database.

Returns None if block is not found.

fn pending_block( &self, ) -> Result<Option<SealedBlock<<Self::Block as Block>::Header, <Self::Block as Block>::Body>>, ProviderError>

Returns the pending block if available

Note: This returns a SealedBlockFor because it’s expected that this is sealed by the provider and the caller does not know the hash.

fn pending_block_with_senders( &self, ) -> Result<Option<SealedBlockWithSenders<Self::Block>>, ProviderError>

Returns the pending block if available

Note: This returns a SealedBlockWithSenders because it’s expected that this is sealed by the provider and the caller does not know the hash.

fn pending_block_and_receipts( &self, ) -> Result<Option<(SealedBlock<<Self::Block as Block>::Header, <Self::Block as Block>::Body>, Vec<Self::Receipt>)>, ProviderError>

Returns the pending block and receipts if available.

fn block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<BlockWithSenders<Self::Block>>, ProviderError>

Returns the block with senders with matching number or hash from database.

Returns the block’s transactions in the requested variant.

Returns None if block is not found.

fn sealed_block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<SealedBlockWithSenders<Self::Block>>, ProviderError>

Returns the sealed block with senders with matching number or hash from database.

Returns the block’s transactions in the requested variant.

Returns None if block is not found.

fn block_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<Self::Block>, ProviderError>

Returns all blocks in the given inclusive range.

Note: returns only available blocks

fn block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<BlockWithSenders<Self::Block>>, ProviderError>

Returns a range of blocks from the database, along with the senders of each transaction in the blocks.

fn sealed_block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<SealedBlockWithSenders<Self::Block>>, ProviderError>

Returns a range of sealed blocks from the database, along with the senders of each transaction in the blocks.

Provided Methods§

fn block_by_hash( &self, hash: FixedBytes<32>, ) -> Result<Option<Self::Block>, ProviderError>

Returns the block with matching hash from the database.

Returns None if block is not found.

fn block_by_number( &self, num: u64, ) -> Result<Option<Self::Block>, ProviderError>

Returns the block with matching number from database.

Returns None if block is not found.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl<T> BlockReader for &T
where T: BlockReader,

§

type Block = <T as BlockReader>::Block

§

fn find_block_by_hash( &self, hash: FixedBytes<32>, source: BlockSource, ) -> Result<Option<<&T as BlockReader>::Block>, ProviderError>

§

fn block( &self, id: HashOrNumber, ) -> Result<Option<<&T as BlockReader>::Block>, ProviderError>

§

fn pending_block( &self, ) -> Result<Option<SealedBlock<<<&T as BlockReader>::Block as Block>::Header, <<&T as BlockReader>::Block as Block>::Body>>, ProviderError>

§

fn pending_block_with_senders( &self, ) -> Result<Option<SealedBlockWithSenders<<&T as BlockReader>::Block>>, ProviderError>

§

fn pending_block_and_receipts( &self, ) -> Result<Option<(SealedBlock<<<&T as BlockReader>::Block as Block>::Header, <<&T as BlockReader>::Block as Block>::Body>, Vec<<&T as ReceiptProvider>::Receipt>)>, ProviderError>

§

fn block_by_hash( &self, hash: FixedBytes<32>, ) -> Result<Option<<&T as BlockReader>::Block>, ProviderError>

§

fn block_by_number( &self, num: u64, ) -> Result<Option<<&T as BlockReader>::Block>, ProviderError>

§

fn block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<BlockWithSenders<<&T as BlockReader>::Block>>, ProviderError>

§

fn sealed_block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<SealedBlockWithSenders<<&T as BlockReader>::Block>>, ProviderError>

§

fn block_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<<&T as BlockReader>::Block>, ProviderError>

§

fn block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<BlockWithSenders<<&T as BlockReader>::Block>>, ProviderError>

§

fn sealed_block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<SealedBlockWithSenders<<&T as BlockReader>::Block>>, ProviderError>

§

impl<T> BlockReader for Arc<T>
where T: BlockReader,

§

type Block = <T as BlockReader>::Block

§

fn find_block_by_hash( &self, hash: FixedBytes<32>, source: BlockSource, ) -> Result<Option<<Arc<T> as BlockReader>::Block>, ProviderError>

§

fn block( &self, id: HashOrNumber, ) -> Result<Option<<Arc<T> as BlockReader>::Block>, ProviderError>

§

fn pending_block( &self, ) -> Result<Option<SealedBlock<<<Arc<T> as BlockReader>::Block as Block>::Header, <<Arc<T> as BlockReader>::Block as Block>::Body>>, ProviderError>

§

fn pending_block_with_senders( &self, ) -> Result<Option<SealedBlockWithSenders<<Arc<T> as BlockReader>::Block>>, ProviderError>

§

fn pending_block_and_receipts( &self, ) -> Result<Option<(SealedBlock<<<Arc<T> as BlockReader>::Block as Block>::Header, <<Arc<T> as BlockReader>::Block as Block>::Body>, Vec<<Arc<T> as ReceiptProvider>::Receipt>)>, ProviderError>

§

fn block_by_hash( &self, hash: FixedBytes<32>, ) -> Result<Option<<Arc<T> as BlockReader>::Block>, ProviderError>

§

fn block_by_number( &self, num: u64, ) -> Result<Option<<Arc<T> as BlockReader>::Block>, ProviderError>

§

fn block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<BlockWithSenders<<Arc<T> as BlockReader>::Block>>, ProviderError>

§

fn sealed_block_with_senders( &self, id: HashOrNumber, transaction_kind: TransactionVariant, ) -> Result<Option<SealedBlockWithSenders<<Arc<T> as BlockReader>::Block>>, ProviderError>

§

fn block_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<<Arc<T> as BlockReader>::Block>, ProviderError>

§

fn block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<BlockWithSenders<<Arc<T> as BlockReader>::Block>>, ProviderError>

§

fn sealed_block_with_senders_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<SealedBlockWithSenders<<Arc<T> as BlockReader>::Block>>, ProviderError>

Implementors§