diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index f627f969..ec6a9dfd 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -97,7 +97,8 @@ pub struct Wallet { pub type Update = LocalUpdate; // /// The changeset produced internally by applying an update. -pub(crate) type ChangeSet = LocalChangeSet; +pub type ChangeSet = LocalChangeSet; + /// The address index selection strategy to use to derived an address from the wallet's external /// descriptor. See [`Wallet::get_address`]. If you're unsure which one to use use `WalletIndex::New`. #[derive(Debug)] diff --git a/crates/electrum/src/v2.rs b/crates/electrum/src/v2.rs index 3ddb0102..bedfdfac 100644 --- a/crates/electrum/src/v2.rs +++ b/crates/electrum/src/v2.rs @@ -30,20 +30,22 @@ impl Default for ElectrumUpdate { } } -impl<'a, K, A: Anchor> ElectrumUpdate { - pub fn missing_full_txs( - &'a self, - graph: &'a TxGraph, - ) -> impl Iterator + 'a { +impl ElectrumUpdate { + pub fn missing_full_txs(&self, graph: &TxGraph) -> Vec { self.graph_update .keys() .filter(move |&&txid| graph.as_ref().get_tx(txid).is_none()) + .cloned() + .collect() } - pub fn finalize(self, seen_at: Option, new_txs: T) -> LocalUpdate - where - T: IntoIterator, - { + pub fn finalize( + self, + client: &Client, + seen_at: Option, + missing: Vec, + ) -> Result, Error> { + let new_txs = client.batch_transaction_get(&missing)?; let mut graph_update = TxGraph::::new(new_txs); for (txid, anchors) in self.graph_update { if let Some(seen_at) = seen_at { @@ -53,11 +55,11 @@ impl<'a, K, A: Anchor> ElectrumUpdate { let _ = graph_update.insert_anchor(txid, anchor); } } - LocalUpdate { + Ok(LocalUpdate { keychain: self.keychain_update, graph: graph_update, chain: self.chain_update, - } + }) } } @@ -68,16 +70,13 @@ impl ElectrumUpdate { /// **Note:** The confirmation time might not be precisely correct if there has been a reorg. /// Electrum's API intends that we use the merkle proof API, we should change `bdk_electrum` to /// use it. - pub fn finalize_as_confirmation_time( + pub fn finalize_as_confirmation_time( self, client: &Client, seen_at: Option, - new_txs: T, - ) -> Result, Error> - where - T: IntoIterator, - { - let update = self.finalize(seen_at, new_txs); + missing: Vec, + ) -> Result, Error> { + let update = self.finalize(client, seen_at, missing)?; let relevant_heights = { let mut visited_heights = HashSet::new(); @@ -111,7 +110,7 @@ impl ElectrumUpdate { .anchors .into_iter() .map(|(height_anchor, txid)| { - let confirmation_height = dbg!(height_anchor.confirmation_height); + let confirmation_height = height_anchor.confirmation_height; let confirmation_time = height_to_time[&confirmation_height]; let time_anchor = ConfirmationTimeAnchor { anchor_block: height_anchor.anchor_block, diff --git a/example-crates/example_electrum/src/main.rs b/example-crates/example_electrum/src/main.rs index f8d2e6af..cfd06c30 100644 --- a/example-crates/example_electrum/src/main.rs +++ b/example-crates/example_electrum/src/main.rs @@ -278,20 +278,15 @@ fn main() -> anyhow::Result<()> { let missing_txids = { let graph = &*graph.lock().unwrap(); - response - .missing_full_txs(graph.graph()) - .cloned() - .collect::>() + response.missing_full_txs(graph.graph()) }; - let new_txs = client - .batch_transaction_get(&missing_txids) - .context("fetching full transactions")?; let now = std::time::UNIX_EPOCH .elapsed() .expect("must get time") .as_secs(); - let final_update = response.finalize(Some(now), new_txs); + + let final_update = response.finalize(&client, Some(now), missing_txids)?; let db_changeset = { let mut chain = chain.lock().unwrap();