diff --git a/CHANGELOG.md b/CHANGELOG.md index e0ec03d1..53c61cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details. - Fixed `warn!` messages, including the mainnet notice, being hidden unless `RUST_LOG` was set; warnings are now shown by default - Added `hwi` feature with a hardware wallet `hwi` command to list connected devices, register a wallet policy, display a receive address, and sign PSBTs. Supports Ledger, Coldcard, BitBox02, Jade and Specter. - Replaced plain `wallets` with `wallets list`, and added `wallets delete ` for unused saved wallet configurations. +- Gated full-scan `stop_gap` to Electrum and Esplora, and made the Esplora parallel-request override optional ## [4.0.0] diff --git a/src/handlers/online.rs b/src/handlers/online.rs index 25baf889..c8bb23f5 100644 --- a/src/handlers/online.rs +++ b/src/handlers/online.rs @@ -82,10 +82,14 @@ impl OnlineWalletSubCommand { #[derive(Parser, Debug, PartialEq, Clone, Eq)] pub struct FullScanCommand { /// Stop searching addresses for transactions after finding an unused gap of this length. + #[cfg(any(feature = "electrum", feature = "esplora"))] #[arg(env = "STOP_GAP", long = "scan-stop-gap", default_value = "20")] stop_gap: usize, - #[clap(long, default_value = "5")] - pub parallel_request: usize, + + /// Override the Esplora wallet's configured parallel request count. + #[cfg(feature = "esplora")] + #[arg(long)] + pub parallel_request: Option, } #[cfg(any( @@ -132,7 +136,11 @@ impl AsyncAppCommand>> for FullScanCommand { parallel_requests, } => { let update = client - .full_scan(request, self.stop_gap, *parallel_requests) + .full_scan( + request, + self.stop_gap, + self.parallel_request.unwrap_or(*parallel_requests), + ) .await .map_err(|e| *e)?; let events = wallet.apply_update_events(update)?; @@ -196,6 +204,39 @@ impl AsyncAppCommand>> for FullScanCommand { } } +#[cfg(test)] +mod tests { + use super::FullScanCommand; + use clap::Parser; + + #[test] + fn stop_gap_is_gated_to_supported_backends() { + #[cfg(any(feature = "electrum", feature = "esplora"))] + { + let default = FullScanCommand::try_parse_from(["bdk-cli"]).unwrap(); + assert_eq!(default.stop_gap, 20); + let custom = + FullScanCommand::try_parse_from(["bdk-cli", "--scan-stop-gap", "42"]).unwrap(); + assert_eq!(custom.stop_gap, 42); + } + + #[cfg(not(any(feature = "electrum", feature = "esplora")))] + assert!(FullScanCommand::try_parse_from(["bdk-cli", "--scan-stop-gap", "42"]).is_err()); + } + + #[cfg(feature = "esplora")] + #[test] + fn parallel_request_overrides_or_uses_wallet_config() { + let configured = 7; + let default = FullScanCommand::try_parse_from(["bdk-cli"]).unwrap(); + assert_eq!(default.parallel_request.unwrap_or(configured), configured); + + let custom = + FullScanCommand::try_parse_from(["bdk-cli", "--parallel-request", "2"]).unwrap(); + assert_eq!(custom.parallel_request.unwrap_or(configured), 2); + } +} + #[derive(Parser, Debug, PartialEq, Eq, Clone)] pub struct SyncCommand;