@@ -71,11 +71,10 @@ impl<N: Network> EventScanner<SyncFromLatestEvents, N> {
7171 ///
7272 /// # Errors
7373 ///
74- /// * [`ScannerError::ServiceShutdown`] - if the internal block-range service cannot be started.
7574 /// * [`ScannerError::Timeout`] - if an RPC call required for startup times out.
7675 /// * [`ScannerError::RpcError`] - if an RPC call required for startup fails.
7776 #[ allow( clippy:: missing_panics_doc) ]
78- pub async fn start ( self ) -> Result < ( ) , ScannerError > {
77+ pub async fn start ( mut self ) -> Result < ( ) , ScannerError > {
7978 let count = self . config . count ;
8079 let provider = self . block_range_scanner . provider ( ) . clone ( ) ;
8180 let listeners = self . listeners . clone ( ) ;
@@ -84,16 +83,17 @@ impl<N: Network> EventScanner<SyncFromLatestEvents, N> {
8483
8584 info ! ( count = count, "Starting scanner, mode: fetch latest events and switch to live" ) ;
8685
87- let client = self . block_range_scanner . run ( ) ?;
88-
8986 // Fetch the latest block number.
9087 // This is used to determine the starting point for the rewind stream and the live
9188 // stream. We do this before starting the streams to avoid a race condition
9289 // where the latest block changes while we're setting up the streams.
9390 let latest_block = provider. get_block_number ( ) . await ?;
9491
9592 // Setup rewind and live streams to run in parallel.
96- let rewind_stream = client. rewind ( latest_block, BlockNumberOrTag :: Earliest ) . await ?;
93+ let rewind_stream = self
94+ . block_range_scanner
95+ . stream_rewind ( latest_block, BlockNumberOrTag :: Earliest )
96+ . await ?;
9797
9898 // Start streaming...
9999 tokio:: spawn ( async move {
@@ -114,17 +114,20 @@ impl<N: Network> EventScanner<SyncFromLatestEvents, N> {
114114 // We actually rely on the sync mode for the live stream, as more blocks could have been
115115 // minted while the scanner was collecting the latest `count` events.
116116 // Note: Sync mode will notify the client when it switches to live streaming.
117- let sync_stream =
118- match client. stream_from ( latest_block + 1 , self . config . block_confirmations ) . await {
119- Ok ( stream) => stream,
120- Err ( e) => {
121- error ! ( error = %e, "Error during sync mode setup" ) ;
122- for listener in listeners {
123- _ = listener. sender . try_stream ( e. clone ( ) ) . await ;
124- }
125- return ;
117+ let sync_stream = match self
118+ . block_range_scanner
119+ . stream_from ( latest_block + 1 , self . config . block_confirmations )
120+ . await
121+ {
122+ Ok ( stream) => stream,
123+ Err ( e) => {
124+ error ! ( error = %e, "Error during sync mode setup" ) ;
125+ for listener in listeners {
126+ _ = listener. sender . try_stream ( e. clone ( ) ) . await ;
126127 }
127- } ;
128+ return ;
129+ }
130+ } ;
128131
129132 // Start the live (sync) stream.
130133 handle_stream (
0 commit comments