Skip to content

Commit f42f8b8

Browse files
vladimirfomeneevanlinjin
authored andcommitted
refactor: Allow for no chain update
1 parent 68572bf commit f42f8b8

File tree

2 files changed

+9
-5
lines changed
  • crates/bdk/src/wallet
  • example-crates/wallet_electrum/src

2 files changed

+9
-5
lines changed

crates/bdk/src/wallet/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct WalletUpdate<K, A> {
110110
/// Update for the [`LocalChain`].
111111
///
112112
/// [`LocalChain`]: local_chain::LocalChain
113-
pub chain: local_chain::Update,
113+
pub chain: Option<local_chain::Update>,
114114
}
115115

116116
impl<K, A> WalletUpdate<K, A> {
@@ -119,7 +119,7 @@ impl<K, A> WalletUpdate<K, A> {
119119
Self {
120120
last_active_indices: BTreeMap::new(),
121121
graph: TxGraph::default(),
122-
chain: chain_update,
122+
chain: Some(chain_update),
123123
}
124124
}
125125
}
@@ -1942,7 +1942,11 @@ impl<D> Wallet<D> {
19421942
where
19431943
D: PersistBackend<ChangeSet>,
19441944
{
1945-
let mut changeset = ChangeSet::from(self.chain.apply_update(update.chain)?);
1945+
let mut changeset = match update.chain {
1946+
Some(chain_update) => ChangeSet::from(self.chain.apply_update(chain_update)?),
1947+
None => ChangeSet::default(),
1948+
};
1949+
19461950
let (_, index_changeset) = self
19471951
.indexed_graph
19481952
.index

example-crates/wallet_electrum/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6464
let wallet_update = WalletUpdate {
6565
last_active_indices: keychain_update,
6666
graph: graph_update,
67-
chain: local_chain::Update {
67+
chain: Some(local_chain::Update {
6868
tip: update_tip,
6969
introduce_older_blocks: true,
70-
},
70+
}),
7171
};
7272
wallet.apply_update(wallet_update)?;
7373
wallet.commit()?;

0 commit comments

Comments
 (0)