]> Untitled Git - bdk/commitdiff
fix: no premature collect
author志宇 <hello@evanlinjin.me>
Fri, 2 Aug 2024 09:38:27 +0000 (09:38 +0000)
committer志宇 <hello@evanlinjin.me>
Wed, 14 Aug 2024 08:16:57 +0000 (08:16 +0000)
crates/chain/src/spk_client.rs
crates/electrum/src/bdk_electrum_client.rs
example-crates/example_electrum/src/main.rs
example-crates/example_esplora/src/main.rs
example-crates/wallet_electrum/src/main.rs

index 215273729086a773de1cc2e27172949a7c995dbc..3909d11f472006ad11391bc4a2f197c4f66cdf32 100644 (file)
@@ -110,14 +110,7 @@ impl<K: Clone + Ord + core::fmt::Debug + Send + Sync> SyncRequestBuilder<(K, u32
         indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
         spk_range: impl core::ops::RangeBounds<K>,
     ) -> Self {
-        use crate::alloc::borrow::ToOwned;
-        use crate::alloc::vec::Vec;
-        self.spks_with_labels(
-            indexer
-                .revealed_spks(spk_range)
-                .map(|(i, spk)| (i, spk.to_owned()))
-                .collect::<Vec<_>>(),
-        )
+        self.spks_with_labels(indexer.revealed_spks(spk_range))
     }
 
     /// Add [`Script`]s that are revealed by the `indexer` but currently unused.
@@ -125,14 +118,7 @@ impl<K: Clone + Ord + core::fmt::Debug + Send + Sync> SyncRequestBuilder<(K, u32
         self,
         indexer: &crate::indexer::keychain_txout::KeychainTxOutIndex<K>,
     ) -> Self {
-        use crate::alloc::borrow::ToOwned;
-        use crate::alloc::vec::Vec;
-        self.spks_with_labels(
-            indexer
-                .unused_spks()
-                .map(|(i, spk)| (i, spk.to_owned()))
-                .collect::<Vec<_>>(),
-        )
+        self.spks_with_labels(indexer.unused_spks())
     }
 }
 
index 3584e8bb623535769f7ac6d4b004dcf8e8093114..1458e2bd9661e2636920a0c02897c859619681ec 100644 (file)
@@ -205,19 +205,16 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             None => None,
         };
 
-        let full_scan_request = FullScanRequest::builder()
-            .spks_for_keychain(
-                (),
-                request
-                    .iter_spks()
-                    .enumerate()
-                    .map(|(i, spk)| (i as u32, spk))
-                    .collect::<Vec<_>>(),
-            )
-            .build();
-        let mut graph_update = self
-            .full_scan(full_scan_request, usize::MAX, batch_size, false)?
-            .graph_update;
+        let mut graph_update = TxGraph::<ConfirmationBlockTime>::default();
+        self.populate_with_spks(
+            &mut graph_update,
+            request
+                .iter_spks()
+                .enumerate()
+                .map(|(i, spk)| (i as u32, spk)),
+            usize::MAX,
+            batch_size,
+        )?;
         self.populate_with_txids(&mut graph_update, request.iter_txids())?;
         self.populate_with_outpoints(&mut graph_update, request.iter_outpoints())?;
 
index bcb0b3ed53058b9d129748190c00a2510d7f9872..7ef54f13b6ae40b1043577c7eee2902406ee3625 100644 (file)
@@ -209,22 +209,11 @@ fn main() -> anyhow::Result<()> {
                     });
 
             if all_spks {
-                request = request.spks_with_labels(
-                    graph
-                        .index
-                        .revealed_spks(..)
-                        .map(|(index, spk)| (index, spk.to_owned())),
-                );
+                request = request.spks_with_labels(graph.index.revealed_spks(..));
             }
             if unused_spks {
-                request = request.spks_with_labels(
-                    graph
-                        .index
-                        .unused_spks()
-                        .map(|(index, spk)| (index, spk.to_owned())),
-                );
+                request = request.spks_with_labels(graph.index.unused_spks());
             }
-
             if utxos {
                 let init_outpoints = graph.index.outpoints();
                 request = request.outpoints(
@@ -238,7 +227,6 @@ fn main() -> anyhow::Result<()> {
                         .map(|(_, utxo)| utxo.outpoint),
                 );
             };
-
             if unconfirmed {
                 request = request.txids(
                     graph
index 0ea99c775e095217a72418f6e1cb0b10185da344..7a28ee2372726bc17281bd64f572849240701198 100644 (file)
@@ -230,20 +230,10 @@ fn main() -> anyhow::Result<()> {
                 let chain = chain.lock().unwrap();
 
                 if *all_spks {
-                    request = request.spks_with_labels(
-                        graph
-                            .index
-                            .revealed_spks(..)
-                            .map(|(i, spk)| (i, spk.to_owned())),
-                    );
+                    request = request.spks_with_labels(graph.index.revealed_spks(..));
                 }
                 if unused_spks {
-                    request = request.spks_with_labels(
-                        graph
-                            .index
-                            .unused_spks()
-                            .map(|(index, spk)| (index, spk.to_owned())),
-                    );
+                    request = request.spks_with_labels(graph.index.unused_spks());
                 }
                 if utxos {
                     // We want to search for whether the UTXO is spent, and spent by which
index cda1889d0b77ad0fcf516cb37f473702611499db..e028b4be2e1d2dda0008090228dcf10adaf03005 100644 (file)
@@ -57,10 +57,9 @@ fn main() -> Result<(), anyhow::Error> {
         let mut once = HashSet::<KeychainKind>::new();
         move |k, spk_i, _| {
             if once.insert(k) {
-                print!("\nScanning keychain [{:?}]", k)
-            } else {
-                print!(" {:<3}", spk_i)
+                print!("\nScanning keychain [{:?}]", k);
             }
+            print!(" {:<3}", spk_i);
             stdout.flush().expect("must flush");
         }
     });