/// - `stop_gap`: the full scan for each keychain stops after a gap of script pubkeys with no
/// associated transactions.
/// - `batch_size`: specifies the max number of script pubkeys to request for in a single batch
- /// request.
+ /// request. A `batch_size` of 0 is treated as 1.
/// - `fetch_prev_txouts`: specifies whether we want previous `TxOut`s for fee calculation. Note
/// that this requires additional calls to the Electrum server, but is necessary for
/// calculating the fee on a transaction if your wallet does not own the inputs. Methods like
/// - `request`: struct with data required to perform a spk-based blockchain client sync, see
/// [`SyncRequest`]
/// - `batch_size`: specifies the max number of script pubkeys to request for in a single batch
- /// request
+ /// request. A `batch_size` of 0 is treated as 1.
/// - `fetch_prev_txouts`: specifies whether we want previous `TxOut`s for fee calculation. Note
/// that this requires additional calls to the Electrum server, but is necessary for
/// calculating the fee on a transaction if your wallet does not own the inputs. Methods like
) -> Result<Option<u32>, Error> {
let mut unused_spk_count = 0_usize;
let mut last_active_index = Option::<u32>::None;
+ let batch_size = batch_size.max(1);
loop {
let spks = (0..batch_size)
Ok(())
}
+
+/// A `batch_size` of 0 must not make `sync` or `full_scan` skip their scripts.
+///
+/// The server drops every connection, so a scan that actually requests something returns an error.
+/// If no request is made, the scan returns an empty `Ok`.
+#[test]
+fn test_zero_batch_size() -> anyhow::Result<()> {
+ let listener = std::net::TcpListener::bind("127.0.0.1:0")?;
+ let url = format!("tcp://{}", listener.local_addr()?);
+ std::thread::spawn(move || listener.incoming().for_each(drop));
+
+ let config = electrum_client::ConfigBuilder::new().retry(0).build();
+ let client = BdkElectrumClient::new(electrum_client::Client::from_config(&url, config)?);
+
+ let response = client.sync(SyncRequest::builder().spks([get_test_spk()]), 0, false);
+ assert!(
+ response.is_err(),
+ "sync skipped its script and returned {response:?}"
+ );
+
+ let request = FullScanRequest::builder().spks_for_keychain(0u32, [(0, get_test_spk())]);
+ let response = client.full_scan(request, 3, 0, false);
+ assert!(
+ response.is_err(),
+ "full scan skipped its script and returned {response:?}"
+ );
+ Ok(())
+}