]> Untitled Git - bdk-cli/commitdiff
refactor(full_scan): share the stop-gap rejection check
authoremma31-dev <emmanuelfidel07@gmail.com>
Fri, 13 Nov 2026 12:05:07 +0000 (13:05 +0100)
committeremma31-dev <emmanuelfidel07@gmail.com>
Fri, 13 Nov 2026 12:06:19 +0000 (13:06 +0100)
The RPC and CBF arms carried an identical `--scan-stop-gap` rejection block,
each with its own `electrum`/`esplora` cfg. Move the check into a
`reject_stop_gap` helper next to `stop_gap` so there is one copy of the message
and one gate.

No behaviour change.

src/handlers/online.rs

index 0b7342b8be5083616db34b02abf1acccbcfa7b01..d28d9ed48b20831341fbad02e29a834a9bc3942d 100644 (file)
@@ -121,6 +121,21 @@ impl FullScanCommand {
     }
 }
 
+#[cfg(any(feature = "rpc", feature = "cbf"))]
+impl FullScanCommand {
+    /// Rejects `--scan-stop-gap` for backends that do not use it: RPC walks blocks and CBF
+    /// follows the filter lookahead, so neither reads `stop_gap`.
+    fn reject_stop_gap(&self) -> Result<(), Error> {
+        #[cfg(any(feature = "electrum", feature = "esplora"))]
+        if self.stop_gap.is_some() {
+            return Err(Error::Generic(
+                "`--scan-stop-gap` is only supported by the electrum and esplora backends".into(),
+            ));
+        }
+        Ok(())
+    }
+}
+
 #[cfg(any(
     feature = "electrum",
     feature = "esplora",
@@ -173,13 +188,7 @@ impl AsyncAppCommand<AppContext<OnlineOperations<'_>>> for FullScanCommand {
             }
             #[cfg(feature = "rpc")]
             RpcClient { client } => {
-                #[cfg(any(feature = "electrum", feature = "esplora"))]
-                if self.stop_gap.is_some() {
-                    return Err(Error::Generic(
-                        "`--scan-stop-gap` is only supported by the electrum and esplora backends"
-                            .into(),
-                    ));
-                }
+                self.reject_stop_gap()?;
 
                 let blockchain_info = client.get_blockchain_info()?;
 
@@ -228,13 +237,7 @@ impl AsyncAppCommand<AppContext<OnlineOperations<'_>>> for FullScanCommand {
 
             #[cfg(feature = "cbf")]
             KyotoClient { client } => {
-                #[cfg(any(feature = "electrum", feature = "esplora"))]
-                if self.stop_gap.is_some() {
-                    return Err(Error::Generic(
-                        "`--scan-stop-gap` is only supported by the electrum and esplora backends"
-                            .into(),
-                    ));
-                }
+                self.reject_stop_gap()?;
 
                 sync_kyoto_client(wallet, client).await?;
             }