Skip to content

Commit

Permalink
refactor: Allow for no chain update
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirfomene committed Aug 24, 2023
1 parent ebe28bd commit 5ca099f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions crates/bdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub struct WalletUpdate<K, A> {
/// Update for the [`LocalChain`].
///
/// [`LocalChain`]: local_chain::LocalChain
pub chain: local_chain::Update,
pub chain: Option<local_chain::Update>,
}

impl<K, A> WalletUpdate<K, A> {
Expand All @@ -118,7 +118,7 @@ impl<K, A> WalletUpdate<K, A> {
Self {
last_active_indices: BTreeMap::new(),
graph: TxGraph::default(),
chain: chain_update,
chain: Some(chain_update),
}
}
}
Expand Down Expand Up @@ -1804,7 +1804,11 @@ impl<D> Wallet<D> {
where
D: PersistBackend<ChangeSet>,
{
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
Expand Down
4 changes: 2 additions & 2 deletions example-crates/wallet_electrum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let wallet_update = WalletUpdate {
last_active_indices: electrum_update.keychain_update,
graph: electrum_update.graph_update,
chain: local_chain::Update {
chain: Some(local_chain::Update {
tip: electrum_update.new_tip,
introduce_older_blocks: true,
},
}),
};
wallet.apply_update(wallet_update)?;
wallet.commit()?;
Expand Down

0 comments on commit 5ca099f

Please sign in to comment.