11#![ allow( unused) ]
22
3- use std:: { future, marker:: PhantomData , time:: Duration } ;
3+ use std:: { future, marker:: PhantomData , ops :: Range , time:: Duration } ;
44
55use tokio:: sync:: mpsc:: { self , Receiver , Sender } ;
66use tokio_stream:: wrappers:: ReceiverStream ;
@@ -57,7 +57,7 @@ pub type OnBlocksFunc<N> =
5757pub struct BlockScannerBuilder < N : Network > {
5858 blocks_read_per_epoch : usize ,
5959 start_height : BlockNumberOrTag ,
60- end_height : BlockNumberOrTag ,
60+ end_height : Option < BlockNumberOrTag > ,
6161 on_blocks : OnBlocksFunc < N > ,
6262 reorg_rewind_depth : u64 ,
6363 retry_interval : Duration ,
@@ -75,8 +75,8 @@ impl<N: Network> BlockScannerBuilder<N> {
7575 pub fn new ( ) -> Self {
7676 Self {
7777 blocks_read_per_epoch : DEFAULT_BLOCKS_READ_PER_EPOCH ,
78- start_height : BlockNumberOrTag :: Earliest ,
79- end_height : BlockNumberOrTag :: Latest ,
78+ start_height : BlockNumberOrTag :: Latest ,
79+ end_height : None ,
8080 on_blocks : |_, _, _| Ok ( ( ) ) ,
8181 reorg_rewind_depth : DEFAULT_REORG_REWIND_DEPTH ,
8282 retry_interval : DEFAULT_RETRY_INTERVAL ,
@@ -98,7 +98,7 @@ impl<N: Network> BlockScannerBuilder<N> {
9898
9999 #[ must_use]
100100 pub fn with_end_height ( & mut self , end_height : BlockNumberOrTag ) -> & mut Self {
101- self . end_height = end_height;
101+ self . end_height = Some ( end_height) ;
102102 self
103103 }
104104
@@ -187,7 +187,7 @@ pub struct BlockScanner<P: Provider<N>, N: Network> {
187187 provider : P ,
188188 blocks_read_per_epoch : usize ,
189189 start_height : BlockNumberOrTag ,
190- end_height : BlockNumberOrTag ,
190+ end_height : Option < BlockNumberOrTag > ,
191191 current : Header ,
192192 on_blocks : OnBlocksFunc < N > ,
193193 is_end : bool ,
@@ -202,7 +202,7 @@ where
202202 P : Provider < N > ,
203203 N : Network ,
204204{
205- pub async fn start ( & self ) -> ReceiverStream < Result < N :: BlockResponse , BlockScannerError > > {
205+ pub async fn start ( & self ) -> ReceiverStream < Result < Range < u64 > , BlockScannerError > > {
206206 let ( sender, receiver) = mpsc:: channel ( self . blocks_read_per_epoch ) ;
207207
208208 let receiver_stream = ReceiverStream :: new ( receiver) ;
@@ -247,8 +247,8 @@ mod tests {
247247 fn test_builder_defaults ( ) {
248248 let builder = BlockScannerBuilder :: < Ethereum > :: new ( ) ;
249249 assert_eq ! ( builder. blocks_read_per_epoch, DEFAULT_BLOCKS_READ_PER_EPOCH ) ;
250- assert ! ( matches!( builder. start_height, BlockNumberOrTag :: Earliest ) ) ;
251- assert ! ( matches! ( builder. end_height, BlockNumberOrTag :: Latest ) ) ;
250+ assert ! ( matches!( builder. start_height, BlockNumberOrTag :: Latest ) ) ;
251+ assert ! ( builder. end_height. is_none ( ) ) ;
252252 assert_eq ! ( builder. reorg_rewind_depth, DEFAULT_REORG_REWIND_DEPTH ) ;
253253 assert_eq ! ( builder. retry_interval, DEFAULT_RETRY_INTERVAL ) ;
254254 assert_eq ! ( builder. block_confirmations, DEFAULT_BLOCK_CONFIRMATIONS ) ;
@@ -268,7 +268,7 @@ mod tests {
268268
269269 assert_eq ! ( builder. blocks_read_per_epoch, 25 ) ;
270270 assert ! ( matches!( builder. start_height, BlockNumberOrTag :: Earliest ) ) ;
271- assert ! ( matches!( builder. end_height, BlockNumberOrTag :: Latest ) ) ;
271+ assert ! ( matches!( builder. end_height, Some ( BlockNumberOrTag :: Latest ) ) ) ;
272272 assert_eq ! ( builder. reorg_rewind_depth, 5 ) ;
273273 assert_eq ! ( builder. retry_interval, interval) ;
274274 assert_eq ! ( builder. block_confirmations, 12 ) ;
0 commit comments