From 7e91849f7c1896d2bdc4affc329eb50b3411828c Mon Sep 17 00:00:00 2001 From: 448-OG Date: Wed, 13 Sep 2023 14:49:30 +0300 Subject: [PATCH 1/6] BREAKING CHANGE: In `electrum` crate the method `scan` of trait `ElectrumExt` no longer takes `txids` and `outpoints` as arguments Fix: `example_electrum` and `wallet_electrum` in `example-crates` no longer take values for these arguments that implement the `scan` method of trait `ElectrumExt` --- crates/electrum/src/electrum_ext.rs | 26 +++++++-------------- example-crates/example_electrum/src/main.rs | 9 +------ example-crates/wallet_electrum/src/main.rs | 2 +- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index 7ac16a046..eff1eb63d 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -146,12 +146,10 @@ pub trait ElectrumExt { /// 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( + 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>; @@ -163,8 +161,8 @@ pub trait ElectrumExt { &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 +170,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 +191,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/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index a05e85c57..0c8e946d7 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 { 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!(); From 2fa5fc606884b133ba86b5b166069c078b3c5b4b Mon Sep 17 00:00:00 2001 From: 448-OG Date: Wed, 13 Sep 2023 16:24:52 +0300 Subject: [PATCH 2/6] BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain` BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan_without_keychain` to `sync` Fix: Modify the `example_electrum` and `wallet_electrum` examples to use new methods from `ElectrumExt` trait --- crates/electrum/src/electrum_ext.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index eff1eb63d..426e0aa7f 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -139,13 +139,14 @@ 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. +<<<<<<< HEAD +======= + /// ##### NOTE: Scanning with keychain is very inefficient and should be used only when restoring + /// from seed words. +>>>>>>> 5a57229 (BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain`) fn scan_with_keychain( &self, prev_tip: Option, @@ -157,7 +158,7 @@ pub trait ElectrumExt { /// Convenience method to call [`scan`] without requiring a keychain. /// /// [`scan`]: ElectrumExt::scan - fn scan_without_keychain( + fn sync( &self, prev_tip: Option, misc_spks: impl IntoIterator, @@ -170,6 +171,7 @@ pub trait ElectrumExt { .enumerate() .map(|(i, spk)| (i as u32, spk)); +<<<<<<< HEAD let (electrum_update, _) = self.scan_with_keychain(prev_tip, [((), spk_iter)].into(), usize::MAX, batch_size)?; @@ -178,6 +180,13 @@ pub trait ElectrumExt { } impl ElectrumExt for Client { +======= + self.scan_with_keychain(prev_tip, [((), spk_iter)].into(), usize::MAX, batch_size) + } +} + +impl ElectrumExt for Client { +>>>>>>> 5a57229 (BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain`) fn scan_with_keychain( &self, prev_tip: Option, From 9655e315b41b14282847e29d660b76fc1fb84785 Mon Sep 17 00:00:00 2001 From: 448-OG Date: Wed, 13 Sep 2023 16:33:34 +0300 Subject: [PATCH 3/6] Chore: Run cargo fmt Chore: Implement recommendations from cargo clippy --- crates/bdk/src/wallet/coin_selection.rs | 20 +++++++++--------- crates/bdk/tests/wallet.rs | 2 +- .../chain/tests/test_keychain_txout_index.rs | 2 +- crates/chain/tests/test_tx_graph.rs | 21 ++++++++----------- 4 files changed, 21 insertions(+), 24 deletions(-) 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!( From 2a9a2e0083bbede86e9deb1ab1ca7d7ee7e5099a Mon Sep 17 00:00:00 2001 From: 448-OG Date: Fri, 15 Sep 2023 12:40:37 +0300 Subject: [PATCH 4/6] BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain` BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan_without_keychain` to `sync` Fix: Modify the `example_electrum` and `wallet_electrum` examples to use new methods from `ElectrumExt` trait This commit has been rebased to use commits at hash `c20a4da9fc902a062eb217b39e37a32d9e64a148` The requested updates have been applied using this commits and previous commits are mostly outdated --- crates/electrum/src/electrum_ext.rs | 11 ----------- example-crates/example_electrum/src/main.rs | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index 426e0aa7f..90a422178 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -142,11 +142,8 @@ pub trait ElectrumExt { /// 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. -<<<<<<< HEAD -======= /// ##### NOTE: Scanning with keychain is very inefficient and should be used only when restoring /// from seed words. ->>>>>>> 5a57229 (BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain`) fn scan_with_keychain( &self, prev_tip: Option, @@ -171,7 +168,6 @@ pub trait ElectrumExt { .enumerate() .map(|(i, spk)| (i as u32, spk)); -<<<<<<< HEAD let (electrum_update, _) = self.scan_with_keychain(prev_tip, [((), spk_iter)].into(), usize::MAX, batch_size)?; @@ -180,13 +176,6 @@ pub trait ElectrumExt { } impl ElectrumExt for Client { -======= - self.scan_with_keychain(prev_tip, [((), spk_iter)].into(), usize::MAX, batch_size) - } -} - -impl ElectrumExt for Client { ->>>>>>> 5a57229 (BREAKING CHANGE: In `electrum` crate rename the `ElectrumExt` trait method `scan` to `scan_with_keychain`) fn scan_with_keychain( &self, prev_tip: Option, diff --git a/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index 0c8e946d7..7a5d66d4e 100644 --- a/example-crates/example_electrum/src/main.rs +++ b/example-crates/example_electrum/src/main.rs @@ -245,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()) } From 25fb58aaaae03896ba4c6147fcc0e0060111a1cf Mon Sep 17 00:00:00 2001 From: 448-OG Date: Fri, 15 Sep 2023 17:07:45 +0300 Subject: [PATCH 5/6] Fix: Replace previous docs `ElectrumExt::scan` with `ElectrumClient::scan_with_keychain` This solves the issue where CI tests for docs.rs error on rustdoc warning `--cfg docsrs -Dwarnings` --- crates/electrum/src/electrum_ext.rs | 4 ++-- crates/electrum/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index 90a422178..b1d7dc20d 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -152,9 +152,9 @@ pub trait ElectrumExt { 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 + /// [`scan_with_keychain`]: ElectrumExt::scan_with_keychain fn sync( &self, prev_tip: Option, 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 From 95d08263d7d60d16e0541462a2ac691e29e05b7b Mon Sep 17 00:00:00 2001 From: 448-OG Date: Fri, 15 Sep 2023 17:17:37 +0300 Subject: [PATCH 6/6] docs(electrum): Dropped usage of `NOTE` and replaced it with `Note that ` in the --- crates/electrum/src/electrum_ext.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/electrum/src/electrum_ext.rs b/crates/electrum/src/electrum_ext.rs index b1d7dc20d..242b68970 100644 --- a/crates/electrum/src/electrum_ext.rs +++ b/crates/electrum/src/electrum_ext.rs @@ -142,7 +142,7 @@ pub trait ElectrumExt { /// 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. - /// ##### NOTE: Scanning with keychain is very inefficient and should be used only when restoring + /// Note that scanning with keychain is very inefficient and should be used only when restoring /// from seed words. fn scan_with_keychain( &self,