pub struct BlockRangeScanner<N: Network> { /* private fields */ }Expand description
A BlockRangeScanner connected to a provider.
Implementations§
Source§impl<N: Network> BlockRangeScanner<N>
impl<N: Network> BlockRangeScanner<N>
Sourcepub fn new(
provider: RobustProvider<N>,
max_block_range: u64,
past_blocks_storage_capacity: RingBufferCapacity,
buffer_capacity: usize,
) -> Self
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 interactionsmax_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 detectionbuffer_capacity- Stream buffer capacity (must be > 0)
Sourcepub fn provider(&self) -> &RobustProvider<N>
pub fn provider(&self) -> &RobustProvider<N>
Returns the underlying RobustProvider.
Sourcepub fn buffer_capacity(&self) -> usize
pub fn buffer_capacity(&self) -> usize
Returns the stream buffer capacity.
Sourcepub async fn stream_live(
&self,
block_confirmations: u64,
) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>
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
ScannerError::Timeout- if an RPC call required for startup times out.ScannerError::RpcError- if an RPC call required for startup fails.
Sourcepub async fn stream_historical(
&self,
start_id: impl Into<BlockId>,
end_id: impl Into<BlockId>,
) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>
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 idend_id- The ending block id
§Errors
ScannerError::Timeout- if an RPC call required for startup times out.ScannerError::RpcError- if an RPC call required for startup fails.ScannerError::BlockNotFound- ifstart_idorend_idcannot be resolved.
Sourcepub async fn stream_from(
&self,
start_id: impl Into<BlockId>,
block_confirmations: u64,
) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>
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
ScannerError::Timeout- if an RPC call required for startup times out.ScannerError::RpcError- if an RPC call required for startup fails.ScannerError::BlockNotFound- ifstart_idcannot be resolved.
Sourcepub async fn stream_rewind(
&self,
start_id: impl Into<BlockId>,
end_id: impl Into<BlockId>,
) -> Result<ReceiverStream<BlockScannerResult>, ScannerError>
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:
- A
Notification::ReorgDetectedis emitted with the common ancestor block - The scanner fetches the new tip block at the same height
- Reorged blocks are re-streamed in chronological order (from
common_ancestor + 1up to the new tip) - 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
ScannerError::Timeout- if an RPC call required for startup times out.ScannerError::RpcError- if an RPC call required for startup fails.ScannerError::BlockNotFound- ifstart_idorend_idcannot be resolved.
Trait Implementations§
Auto Trait Implementations§
impl<N> Freeze for BlockRangeScanner<N>
impl<N> !RefUnwindSafe for BlockRangeScanner<N>
impl<N> Send for BlockRangeScanner<N>
impl<N> Sync for BlockRangeScanner<N>
impl<N> Unpin for BlockRangeScanner<N>
impl<N> UnsafeUnpin for BlockRangeScanner<N>
impl<N> !UnwindSafe for BlockRangeScanner<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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