From 9677671849c933d7d320bb92d218f98b128aea83 Mon Sep 17 00:00:00 2001 From: newtonick Date: Mon, 26 Oct 2026 16:41:50 -0400 Subject: [PATCH] feat(electrum): add ElectrumClient.populate_tx_cache Expose BdkElectrumClient::populate_tx_cache, which inserts transactions into the client's transaction cache so that it will not re-fetch them. A new ElectrumClient starts with an empty cache, so the first full_scan or sync on it downloads every transaction the wallet already has, one request each. Passing the wallet's transactions to populate_tx_cache first means the scan only downloads new ones. On a testnet4 wallet with 622 transactions, a full scan on a new client against a Fulcrum server went from 43.0 s to 2.1 s. --- bdk-ffi/src/electrum.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bdk-ffi/src/electrum.rs b/bdk-ffi/src/electrum.rs index 57288c15d..da4844d5e 100644 --- a/bdk-ffi/src/electrum.rs +++ b/bdk-ffi/src/electrum.rs @@ -165,6 +165,15 @@ impl ElectrumClient { Ok(Arc::new(Transaction::from(tx.as_ref().clone()))) } + /// Insert transactions into the transaction cache so that the client will not re-fetch them. + /// + /// Typically used with a new client before a `full_scan` or `sync`, passing the transactions + /// the wallet already has (see `Wallet.transactions`), so that the scan only downloads new ones. + pub fn populate_tx_cache(&self, txs: Vec>) { + self.0 + .populate_tx_cache(txs.iter().map(|tx| BdkTransaction::from(tx.as_ref()))); + } + /// Returns the capabilities of the server. pub fn server_features(&self) -> Result { let res = self