Skip to content

Commit 995e160

Browse files
authored
Turn spawn handles into concrete handler types (#288)
1 parent 97afa8c commit 995e160

File tree

13 files changed

+747
-664
lines changed

13 files changed

+747
-664
lines changed

src/block_range_scanner/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ impl BlockRangeScannerBuilder {
9191
return Err(ScannerError::InvalidBufferCapacity);
9292
}
9393
let provider = provider.into_robust_provider().await?;
94-
Ok(BlockRangeScanner {
94+
Ok(BlockRangeScanner::new(
9595
provider,
96-
max_block_range: self.max_block_range,
97-
past_blocks_storage_capacity: self.past_blocks_storage_capacity,
98-
buffer_capacity: self.buffer_capacity,
99-
})
96+
self.max_block_range,
97+
self.past_blocks_storage_capacity,
98+
self.buffer_capacity,
99+
))
100100
}
101101
}

src/block_range_scanner/scanner.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,31 @@ use alloy::{
102102
/// A [`BlockRangeScanner`] connected to a provider.
103103
#[derive(Debug)]
104104
pub struct BlockRangeScanner<N: Network> {
105-
pub(crate) provider: RobustProvider<N>,
106-
pub(crate) max_block_range: u64,
107-
pub(crate) past_blocks_storage_capacity: RingBufferCapacity,
108-
pub(crate) buffer_capacity: usize,
105+
provider: RobustProvider<N>,
106+
max_block_range: u64,
107+
past_blocks_storage_capacity: RingBufferCapacity,
108+
buffer_capacity: usize,
109109
}
110110

111111
impl<N: Network> BlockRangeScanner<N> {
112+
/// Creates a new [`BlockRangeScanner`] with the specified configuration.
113+
///
114+
/// # Arguments
115+
///
116+
/// * `provider` - The robust provider to use for blockchain interactions
117+
/// * `max_block_range` - Maximum number of blocks per streamed range (must be > 0)
118+
/// * `past_blocks_storage_capacity` - How many past block hashes to keep for reorg detection
119+
/// * `buffer_capacity` - Stream buffer capacity (must be > 0)
120+
#[must_use]
121+
pub fn new(
122+
provider: RobustProvider<N>,
123+
max_block_range: u64,
124+
past_blocks_storage_capacity: RingBufferCapacity,
125+
buffer_capacity: usize,
126+
) -> Self {
127+
Self { provider, max_block_range, past_blocks_storage_capacity, buffer_capacity }
128+
}
129+
112130
/// Returns the underlying [`RobustProvider`].
113131
#[must_use]
114132
pub fn provider(&self) -> &RobustProvider<N> {

src/event_scanner/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::event_scanner::{EventScannerResult, filter::EventFilter};
22
use tokio::sync::mpsc::Sender;
33

44
#[derive(Clone, Debug)]
5-
pub(crate) struct EventListener {
5+
pub struct EventListener {
66
pub filter: EventFilter,
77
pub sender: Sender<EventScannerResult>,
88
}

src/event_scanner/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ pub use filter::EventFilter;
1717
pub use message::{EventScannerResult, Message};
1818
pub use scanner::{
1919
DEFAULT_MAX_CONCURRENT_FETCHES, EventScanner, EventScannerBuilder, Historic, LatestEvents,
20-
Live, SyncFromBlock, SyncFromLatestEvents,
20+
Live, SyncFromBlock, SyncFromLatestEvents, block_range_handler,
2121
};

0 commit comments

Comments
 (0)