Trait BlockProvider

Source
pub trait BlockProvider:
    Send
    + Sync
    + 'static {
    type Block: Block;

    // Required methods
    fn subscribe_blocks(
        &self,
        tx: Sender<Self::Block>,
    ) -> impl Future<Output = ()> + Send;
    fn get_block(
        &self,
        block_number: u64,
    ) -> impl Future<Output = Result<Self::Block>> + Send;

    // Provided method
    fn get_or_fetch_previous_block(
        &self,
        previous_block_hashes: &AllocRingBuffer<B256>,
        current_block_number: u64,
        offset: usize,
    ) -> impl Future<Output = Result<B256>> + Send { ... }
}
Expand description

Supplies consensus client with new blocks sent in tx and a callback to find specific blocks by number to fetch past finalized and safe blocks.

Required Associated Types§

Source

type Block: Block

The block type.

Required Methods§

Source

fn subscribe_blocks( &self, tx: Sender<Self::Block>, ) -> impl Future<Output = ()> + Send

Runs a block provider to send new blocks to the given sender.

Note: This is expected to be spawned in a separate task, and as such it should ignore errors.

Source

fn get_block( &self, block_number: u64, ) -> impl Future<Output = Result<Self::Block>> + Send

Get a past block by number.

Provided Methods§

Source

fn get_or_fetch_previous_block( &self, previous_block_hashes: &AllocRingBuffer<B256>, current_block_number: u64, offset: usize, ) -> impl Future<Output = Result<B256>> + Send

Get previous block hash using previous block hash buffer. If it isn’t available (buffer started more recently than offset), fetch it using get_block.

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§

Source§

impl<'a, T: 'a + BlockProvider + ?Sized> BlockProvider for &'a T
where &'a T: Send + Sync + 'static,

Source§

type Block = <T as BlockProvider>::Block

Source§

fn subscribe_blocks( &self, tx: Sender<Self::Block>, ) -> impl Future<Output = ()> + Send

Source§

fn get_block( &self, block_number: u64, ) -> impl Future<Output = Result<Self::Block>> + Send

Source§

fn get_or_fetch_previous_block( &self, previous_block_hashes: &AllocRingBuffer<B256>, current_block_number: u64, offset: usize, ) -> impl Future<Output = Result<B256>> + Send

Source§

impl<T: BlockProvider + ?Sized> BlockProvider for Box<T>
where Box<T>: Send + Sync + 'static,

Source§

type Block = <T as BlockProvider>::Block

Source§

fn subscribe_blocks( &self, tx: Sender<Self::Block>, ) -> impl Future<Output = ()> + Send

Source§

fn get_block( &self, block_number: u64, ) -> impl Future<Output = Result<Self::Block>> + Send

Source§

fn get_or_fetch_previous_block( &self, previous_block_hashes: &AllocRingBuffer<B256>, current_block_number: u64, offset: usize, ) -> impl Future<Output = Result<B256>> + Send

Source§

impl<T: BlockProvider + ?Sized> BlockProvider for Arc<T>
where Arc<T>: Send + Sync + 'static,

Source§

type Block = <T as BlockProvider>::Block

Source§

fn subscribe_blocks( &self, tx: Sender<Self::Block>, ) -> impl Future<Output = ()> + Send

Source§

fn get_block( &self, block_number: u64, ) -> impl Future<Output = Result<Self::Block>> + Send

Source§

fn get_or_fetch_previous_block( &self, previous_block_hashes: &AllocRingBuffer<B256>, current_block_number: u64, offset: usize, ) -> impl Future<Output = Result<B256>> + Send

Implementors§

Source§

impl<N: Network, PrimitiveBlock> BlockProvider for RpcBlockProvider<N, PrimitiveBlock>
where PrimitiveBlock: Block + 'static,

Source§

type Block = PrimitiveBlock

Source§

impl<RpcBlock, PrimitiveBlock> BlockProvider for EtherscanBlockProvider<RpcBlock, PrimitiveBlock>
where RpcBlock: Serialize + DeserializeOwned + 'static, PrimitiveBlock: Block + 'static,

Source§

type Block = PrimitiveBlock