Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/block_range_scanner/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl BlockRangeScannerBuilder {
return Err(ScannerError::InvalidBufferCapacity);
}
let provider = provider.into_robust_provider().await?;
Ok(BlockRangeScanner {
Ok(BlockRangeScanner::new(
provider,
max_block_range: self.max_block_range,
past_blocks_storage_capacity: self.past_blocks_storage_capacity,
buffer_capacity: self.buffer_capacity,
})
self.max_block_range,
self.past_blocks_storage_capacity,
self.buffer_capacity,
))
}
}
26 changes: 22 additions & 4 deletions src/block_range_scanner/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,31 @@ use alloy::{
/// A [`BlockRangeScanner`] connected to a provider.
#[derive(Debug)]
pub struct BlockRangeScanner<N: Network> {
pub(crate) provider: RobustProvider<N>,
pub(crate) max_block_range: u64,
pub(crate) past_blocks_storage_capacity: RingBufferCapacity,
pub(crate) buffer_capacity: usize,
provider: RobustProvider<N>,
max_block_range: u64,
past_blocks_storage_capacity: RingBufferCapacity,
buffer_capacity: usize,
}

impl<N: Network> BlockRangeScanner<N> {
/// 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)
#[must_use]
pub fn new(
provider: RobustProvider<N>,
max_block_range: u64,
past_blocks_storage_capacity: RingBufferCapacity,
buffer_capacity: usize,
) -> Self {
Self { provider, max_block_range, past_blocks_storage_capacity, buffer_capacity }
}

/// Returns the underlying [`RobustProvider`].
#[must_use]
pub fn provider(&self) -> &RobustProvider<N> {
Expand Down
2 changes: 1 addition & 1 deletion src/event_scanner/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::event_scanner::{EventScannerResult, filter::EventFilter};
use tokio::sync::mpsc::Sender;

#[derive(Clone, Debug)]
pub(crate) struct EventListener {
pub struct EventListener {
pub filter: EventFilter,
pub sender: Sender<EventScannerResult>,
}
2 changes: 1 addition & 1 deletion src/event_scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pub use filter::EventFilter;
pub use message::{EventScannerResult, Message};
pub use scanner::{
DEFAULT_MAX_CONCURRENT_FETCHES, EventScanner, EventScannerBuilder, Historic, LatestEvents,
Live, SyncFromBlock, SyncFromLatestEvents,
Live, SyncFromBlock, SyncFromLatestEvents, block_range_handler,
};
Loading