Skip to content

Commit e78fa2a

Browse files
vladimirfomeneevanlinjin
authored andcommitted
refactor: Allow for no chain update
1 parent 6424562 commit e78fa2a

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
@@ -109,7 +109,7 @@ pub struct WalletUpdate<K, A> {
109109
/// Update for the [`LocalChain`].
110110
///
111111
/// [`LocalChain`]: local_chain::LocalChain
112-
pub chain: local_chain::Update,
112+
pub chain: Option<local_chain::Update>,
113113
}
114114

115115
impl<K, A> WalletUpdate<K, A> {
@@ -118,7 +118,7 @@ impl<K, A> WalletUpdate<K, A> {
118118
Self {
119119
last_active_indices: BTreeMap::new(),
120120
graph: TxGraph::default(),
121-
chain: chain_update,
121+
chain: Some(chain_update),
122122
}
123123
}
124124
}
@@ -1804,7 +1804,11 @@ impl<D> Wallet<D> {
18041804
where
18051805
D: PersistBackend<ChangeSet>,
18061806
{
1807-
let mut changeset = ChangeSet::from(self.chain.apply_update(update.chain)?);
1807+
let mut changeset = match update.chain {
1808+
Some(chain_update) => ChangeSet::from(self.chain.apply_update(chain_update)?),
1809+
None => ChangeSet::default(),
1810+
};
1811+
18081812
let (_, index_changeset) = self
18091813
.indexed_graph
18101814
.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)