diff --git a/crates/bdk/src/wallet/coin_selection.rs b/crates/bdk/src/wallet/coin_selection.rs index c3e84af2b..a0179d31b 100644 --- a/crates/bdk/src/wallet/coin_selection.rs +++ b/crates/bdk/src/wallet/coin_selection.rs @@ -836,7 +836,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 250_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( utxos, vec![], @@ -857,7 +857,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( utxos, vec![], @@ -878,7 +878,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( vec![], utxos, @@ -900,7 +900,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 500_000 + FEE_AMOUNT; - LargestFirstCoinSelection::default() + LargestFirstCoinSelection .coin_select( vec![], utxos, @@ -918,7 +918,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 250_000 + FEE_AMOUNT; - LargestFirstCoinSelection::default() + LargestFirstCoinSelection .coin_select( vec![], utxos, @@ -935,7 +935,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 180_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( vec![], utxos, @@ -956,7 +956,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( utxos, vec![], @@ -977,7 +977,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( vec![], utxos, @@ -999,7 +999,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 600_000 + FEE_AMOUNT; - OldestFirstCoinSelection::default() + OldestFirstCoinSelection .coin_select( vec![], utxos, @@ -1018,7 +1018,7 @@ mod test { let target_amount: u64 = utxos.iter().map(|wu| wu.utxo.txout().value).sum::() - 50; let drain_script = ScriptBuf::default(); - OldestFirstCoinSelection::default() + OldestFirstCoinSelection .coin_select( vec![], utxos, diff --git a/crates/bdk/tests/wallet.rs b/crates/bdk/tests/wallet.rs index aad8c2db2..8d43049ef 100644 --- a/crates/bdk/tests/wallet.rs +++ b/crates/bdk/tests/wallet.rs @@ -3085,7 +3085,7 @@ fn test_taproot_script_spend_sign_exclude_some_leaves() { .values() .map(|(script, version)| TapLeafHash::from_script(script, *version)) .collect(); - let included_script_leaves = vec![script_leaves.pop().unwrap()]; + let included_script_leaves = [script_leaves.pop().unwrap()]; let excluded_script_leaves = script_leaves; assert!( diff --git a/crates/chain/tests/test_keychain_txout_index.rs b/crates/chain/tests/test_keychain_txout_index.rs index c4f434715..849f9e9f8 100644 --- a/crates/chain/tests/test_keychain_txout_index.rs +++ b/crates/chain/tests/test_keychain_txout_index.rs @@ -312,7 +312,7 @@ fn test_wildcard_derivations() { let _ = txout_index.reveal_to_target(&TestKeychain::External, 25); (0..=15) - .chain(vec![17, 20, 23].into_iter()) + .chain(vec![17, 20, 23]) .for_each(|index| assert!(txout_index.mark_used(&TestKeychain::External, index))); assert_eq!(txout_index.next_index(&TestKeychain::External), (26, true)); diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index 4c68f5108..8ab55137b 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -709,18 +709,15 @@ fn test_chain_spends() { let _ = graph.insert_tx(tx_1.clone()); let _ = graph.insert_tx(tx_2.clone()); - [95, 98] - .iter() - .zip([&tx_0, &tx_1].into_iter()) - .for_each(|(ht, tx)| { - let _ = graph.insert_anchor( - tx.txid(), - ConfirmationHeightAnchor { - anchor_block: tip.block_id(), - confirmation_height: *ht, - }, - ); - }); + [95, 98].iter().zip([&tx_0, &tx_1]).for_each(|(ht, tx)| { + let _ = graph.insert_anchor( + tx.txid(), + ConfirmationHeightAnchor { + anchor_block: tip.block_id(), + confirmation_height: *ht, + }, + ); + }); // Assert that confirmed spends are returned correctly. assert_eq!( diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index 7ac16a046..242b68970 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -139,32 +139,28 @@ pub trait ElectrumExt { /// /// - `prev_tip`: the most recent blockchain tip present locally /// - `keychain_spks`: keychains that we want to scan transactions for - /// - `txids`: transactions for which we want updated [`Anchor`]s - /// - `outpoints`: transactions associated with these outpoints (residing, spending) that we - /// want to included in the update - /// /// The scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated /// transactions. `batch_size` specifies the max number of script pubkeys to request for in a /// single batch request. - fn scan( + /// Note that scanning with keychain is very inefficient and should be used only when restoring + /// from seed words. + fn scan_with_keychain( &self, prev_tip: Option, keychain_spks: BTreeMap>, - txids: impl IntoIterator, - outpoints: impl IntoIterator, stop_gap: usize, batch_size: usize, ) -> Result<(ElectrumUpdate, BTreeMap), Error>; - /// Convenience method to call [`scan`] without requiring a keychain. + /// Convenience method to call [`scan_with_keychain`] without requiring a keychain. /// - /// [`scan`]: ElectrumExt::scan - fn scan_without_keychain( + /// [`scan_with_keychain`]: ElectrumExt::scan_with_keychain + fn sync( &self, prev_tip: Option, misc_spks: impl IntoIterator, - txids: impl IntoIterator, - outpoints: impl IntoIterator, + _txids: impl IntoIterator, + _outpoints: impl IntoIterator, batch_size: usize, ) -> Result { let spk_iter = misc_spks @@ -172,26 +168,18 @@ pub trait ElectrumExt { .enumerate() .map(|(i, spk)| (i as u32, spk)); - let (electrum_update, _) = self.scan( - prev_tip, - [((), spk_iter)].into(), - txids, - outpoints, - usize::MAX, - batch_size, - )?; + let (electrum_update, _) = + self.scan_with_keychain(prev_tip, [((), spk_iter)].into(), usize::MAX, batch_size)?; Ok(electrum_update) } } impl ElectrumExt for Client { - fn scan( + fn scan_with_keychain( &self, prev_tip: Option, keychain_spks: BTreeMap>, - txids: impl IntoIterator, - outpoints: impl IntoIterator, stop_gap: usize, batch_size: usize, ) -> Result<(ElectrumUpdate, BTreeMap), Error> { @@ -201,8 +189,8 @@ impl ElectrumExt for Client { .collect::>(); let mut scanned_spks = BTreeMap::<(K, u32), (ScriptBuf, bool)>::new(); - let txids = txids.into_iter().collect::>(); - let outpoints = outpoints.into_iter().collect::>(); + let txids = Vec::<_>::new(); + let outpoints = Vec::<_>::new(); let (electrum_update, keychain_update) = loop { let (tip, _) = construct_update_tip(self, prev_tip.clone())?; diff --git a/crates/electrum/src/lib.rs b/crates/electrum/src/lib.rs index 1e4805379..0f547822e 100644 --- a/crates/electrum/src/lib.rs +++ b/crates/electrum/src/lib.rs @@ -1,6 +1,6 @@ //! This crate is used for updating structures of the [`bdk_chain`] crate with data from electrum. //! -//! The star of the show is the [`ElectrumExt::scan`] method, which scans for relevant blockchain +//! The star of the show is the [`ElectrumExt::scan_with_keychain`] method, which scans for relevant blockchain //! data (via electrum) and outputs updates for [`bdk_chain`] structures as a tuple of form: //! //! ([`bdk_chain::local_chain::Update`], [`RelevantTxids`], `keychain_update`) @@ -17,7 +17,7 @@ //! //! Refer to [`bdk_electrum_example`] for a complete example. //! -//! [`ElectrumClient::scan`]: electrum_client::ElectrumClient::scan +//! [`ElectrumClient::scan_with_keychain`]: electrum_client::ElectrumClient::scan_with_keychain //! [`missing_full_txs`]: RelevantTxids::missing_full_txs //! [`batch_transaction_get`]: electrum_client::ElectrumApi::batch_transaction_get //! [`bdk_electrum_example`]: https://github.com/LLFourn/bdk_core_staging/tree/master/bdk_electrum_example diff --git a/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index a05e85c57..7a5d66d4e 100644 --- a/example-crates/example_electrum/src/main.rs +++ b/example-crates/example_electrum/src/main.rs @@ -146,14 +146,7 @@ fn main() -> anyhow::Result<()> { }; client - .scan( - tip, - keychain_spks, - core::iter::empty(), - core::iter::empty(), - stop_gap, - scan_options.batch_size, - ) + .scan_with_keychain(tip, keychain_spks, stop_gap, scan_options.batch_size) .context("scanning the blockchain")? } ElectrumCommands::Sync { @@ -252,7 +245,7 @@ fn main() -> anyhow::Result<()> { drop((graph, chain)); let electrum_update = client - .scan_without_keychain(tip, spks, txids, outpoints, scan_options.batch_size) + .sync(tip, spks, txids, outpoints, scan_options.batch_size) .context("scanning the blockchain")?; (electrum_update, BTreeMap::new()) } diff --git a/example-crates/wallet_electrum/src/main.rs b/example-crates/wallet_electrum/src/main.rs index a6d7ca520..b2c0d1c5d 100644 --- a/example-crates/wallet_electrum/src/main.rs +++ b/example-crates/wallet_electrum/src/main.rs @@ -61,7 +61,7 @@ fn main() -> Result<(), Box> { relevant_txids, }, keychain_update, - ) = client.scan(prev_tip, keychain_spks, None, None, STOP_GAP, BATCH_SIZE)?; + ) = client.scan_with_keychain(prev_tip, keychain_spks, STOP_GAP, BATCH_SIZE)?; println!();