File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -964,6 +964,41 @@ impl BlockRangeScannerClient {
964964 Ok ( ReceiverStream :: new ( blocks_receiver) )
965965 }
966966
967+ /// Streams blocks in reverse order from `start_height` to `end_height`.
968+ ///
969+ /// # Arguments
970+ ///
971+ /// * `start_height` - The starting block number or tag (defaults to Latest if None).
972+ /// * `end_height` - The ending block number or tag (defaults to Earliest if None).
973+ ///
974+ /// # Errors
975+ ///
976+ /// * `BlockRangeScannerError::ServiceShutdown` - if the service is already shutting down.
977+ pub async fn rewind < BN : Into < BlockNumberOrTag > > (
978+ & self ,
979+ start_height : Option < BN > ,
980+ end_height : Option < BN > ,
981+ ) -> Result < ReceiverStream < BlockRangeMessage > , BlockRangeScannerError > {
982+ let ( blocks_sender, blocks_receiver) = mpsc:: channel ( MAX_BUFFERED_MESSAGES ) ;
983+ let ( response_tx, response_rx) = oneshot:: channel ( ) ;
984+
985+ let command = Command :: Rewind {
986+ sender : blocks_sender,
987+ start_height : start_height. map ( |n| n. into ( ) ) ,
988+ end_height : end_height. map ( |n| n. into ( ) ) ,
989+ response : response_tx,
990+ } ;
991+
992+ self . command_sender
993+ . send ( command)
994+ . await
995+ . map_err ( |_| BlockRangeScannerError :: ServiceShutdown ) ?;
996+
997+ response_rx. await . map_err ( |_| BlockRangeScannerError :: ServiceShutdown ) ??;
998+
999+ Ok ( ReceiverStream :: new ( blocks_receiver) )
1000+ }
1001+
9671002 /// Unsubscribes the current subscriber.
9681003 ///
9691004 /// # Errors
You can’t perform that action at this time.
0 commit comments