From f42f8b8ff19c2e67888b476487e4e5c9edb0d0ff Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Thu, 24 Aug 2023 16:03:47 +0300 Subject: [PATCH] refactor: Allow for no chain update --- crates/bdk/src/wallet/mod.rs | 10 +++++++--- example-crates/wallet_electrum/src/main.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 47dd03de..21ba5ee6 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -110,7 +110,7 @@ pub struct WalletUpdate { /// Update for the [`LocalChain`]. /// /// [`LocalChain`]: local_chain::LocalChain - pub chain: local_chain::Update, + pub chain: Option, } impl WalletUpdate { @@ -119,7 +119,7 @@ impl WalletUpdate { Self { last_active_indices: BTreeMap::new(), graph: TxGraph::default(), - chain: chain_update, + chain: Some(chain_update), } } } @@ -1942,7 +1942,11 @@ impl Wallet { where D: PersistBackend, { - let mut changeset = ChangeSet::from(self.chain.apply_update(update.chain)?); + let mut changeset = match update.chain { + Some(chain_update) => ChangeSet::from(self.chain.apply_update(chain_update)?), + None => ChangeSet::default(), + }; + let (_, index_changeset) = self .indexed_graph .index diff --git a/example-crates/wallet_electrum/src/main.rs b/example-crates/wallet_electrum/src/main.rs index 86ea8a7c..0ea7df48 100644 --- a/example-crates/wallet_electrum/src/main.rs +++ b/example-crates/wallet_electrum/src/main.rs @@ -64,10 +64,10 @@ fn main() -> Result<(), Box> { let wallet_update = WalletUpdate { last_active_indices: keychain_update, graph: graph_update, - chain: local_chain::Update { + chain: Some(local_chain::Update { tip: update_tip, introduce_older_blocks: true, - }, + }), }; wallet.apply_update(wallet_update)?; wallet.commit()?;