From fec72ff2955d660a74b27540166da045e9a3bd71 Mon Sep 17 00:00:00 2001 From: cygnet Date: Wed, 13 Nov 2024 23:40:38 +0100 Subject: [PATCH] Pass interrupt atomic bool to scanner constructor --- src/scanner/scanner.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/scanner/scanner.rs b/src/scanner/scanner.rs index 976a63f..3541403 100644 --- a/src/scanner/scanner.rs +++ b/src/scanner/scanner.rs @@ -22,25 +22,28 @@ use crate::{ updater::Updater, }; -pub struct SpScanner { +pub struct SpScanner<'a> { updater: Box, backend: Box, client: SpClient, + keep_scanning: &'a AtomicBool, // used to interrupt scanning owned_outpoints: HashSet, // used to scan block inputs } -impl SpScanner { +impl<'a> SpScanner<'a> { pub fn new( client: SpClient, updater: Box, backend: Box, owned_outpoints: HashSet, + keep_scanning: &'a AtomicBool, ) -> Self { Self { client, updater, backend, owned_outpoints, + keep_scanning, } } @@ -50,7 +53,6 @@ impl SpScanner { end: Height, dust_limit: Amount, with_cutthrough: bool, - keep_scanning: &AtomicBool, ) -> Result<()> { if start > end { bail!("bigger start than end: {} > {}", start, end); @@ -66,8 +68,7 @@ impl SpScanner { .get_block_data_for_range(range, dust_limit, with_cutthrough); // process blocks using block data stream - self.process_blocks(start, end, block_data_stream, keep_scanning) - .await?; + self.process_blocks(start, end, block_data_stream).await?; // time elapsed for the scan info!( @@ -83,7 +84,6 @@ impl SpScanner { start: Height, end: Height, block_data_stream: impl Stream>, - keep_scanning: &AtomicBool, ) -> Result<()> { pin_mut!(block_data_stream); @@ -371,4 +371,10 @@ impl SpScanner { Ok(false) } } + + fn interrupt_requested(&self) -> bool { + !self + .keep_scanning + .load(std::sync::atomic::Ordering::Relaxed) + } }