Skip to main content

BlockRangeScanner

Struct BlockRangeScanner 

Source
pub struct BlockRangeScanner<N: Network> { /* private fields */ }
Expand description

A BlockRangeScanner connected to a provider.

Implementations§

Source§

impl<N: Network> BlockRangeScanner<N>

Source

pub fn new( provider: RobustProvider<N>, max_block_range: u64, past_blocks_storage_capacity: RingBufferCapacity, buffer_capacity: usize, ) -> Self

Creates a new BlockRangeScanner with the specified configuration.

§Arguments
  • provider - The robust provider to use for blockchain interactions
  • max_block_range - Maximum number of blocks per streamed range (must be > 0)
  • past_blocks_storage_capacity - How many past block hashes to keep for reorg detection
  • buffer_capacity - Stream buffer capacity (must be > 0)
Source

pub fn provider(&self) -> &RobustProvider<N>

Returns the underlying RobustProvider.

Source

pub fn buffer_capacity(&self) -> usize

Returns the stream buffer capacity.

Source

pub async fn stream_live( &self, block_confirmations: u64, ) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>

Streams live blocks starting from the latest block.

§Arguments
  • block_confirmations - Number of confirmations to apply once in live mode.
§Errors
Source

pub async fn stream_historical( &self, start_id: impl Into<BlockId>, end_id: impl Into<BlockId>, ) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>

Streams a batch of historical blocks from start_id to end_id.

§Arguments
  • start_id - The starting block id
  • end_id - The ending block id
§Errors
Source

pub async fn stream_from( &self, start_id: impl Into<BlockId>, block_confirmations: u64, ) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>

Streams blocks starting from start_id and transitions to live mode.

§Arguments
  • start_id - The starting block id.
  • block_confirmations - Number of confirmations to apply once in live mode.
§Errors
Source

pub async fn stream_rewind( &self, start_id: impl Into<BlockId>, end_id: impl Into<BlockId>, ) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>

Streams blocks in reverse order from start_id to end_id.

The start_id block is assumed to be greater than or equal to the end_id block. Blocks are streamed in batches, where each batch is ordered from lower to higher block numbers (chronological order within each batch), but batches themselves progress from newer to older blocks.

§Arguments
  • start_id - The starting block id (higher block number).
  • end_id - The ending block id (lower block number).
§Reorg Handling

Reorg checks are only performed when the specified block range tip is above the current finalized block height. When a reorg is detected:

  1. A Notification::ReorgDetected is emitted with the common ancestor block
  2. The scanner fetches the new tip block at the same height
  3. Reorged blocks are re-streamed in chronological order (from common_ancestor + 1 up to the new tip)
  4. The reverse scan continues from where it left off

If the range tip is at or below the finalized block, no reorg checks are performed since finalized blocks cannot be reorganized.

§Note

The reason reorged blocks are streamed in chronological order is to make it easier to handle reorgs in EventScannerBuilder::latest mode, i.e. to prepend reorged blocks to the result collection, which must maintain chronological order.

§Errors

Trait Implementations§

Source§

impl<N: Debug + Network> Debug for BlockRangeScanner<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more