From a28748c33976312b9e6671636ab7e305323efb03 Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Fri, 25 Aug 2023 12:49:29 +0300 Subject: [PATCH] refactor: Implement Default for WalletUpdate --- crates/bdk/src/wallet/mod.rs | 11 +++++------ example-crates/wallet_esplora_async/src/main.rs | 2 +- example-crates/wallet_esplora_blocking/src/main.rs | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 21ba5ee6..a7fe4d42 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -95,9 +95,9 @@ pub struct Wallet { secp: SecpCtx, } -/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically. +/// A structure to update [`Wallet`]. /// -/// [`LocalChain`]: local_chain::LocalChain +/// It updates [`bdk_chain::keychain::KeychainTxOutIndex`], [`bdk_chain::TxGraph`] and [`local_chain::LocalChain`] atomically. #[derive(Debug, Clone)] pub struct WalletUpdate { /// Contains the last active derivation indices per keychain (`K`), which is used to update the @@ -113,13 +113,12 @@ pub struct WalletUpdate { pub chain: Option, } -impl WalletUpdate { - /// Construct a [`WalletUpdate`] with a given [`local_chain::Update`]. - pub fn new(chain_update: local_chain::Update) -> Self { +impl Default for WalletUpdate { + fn default() -> Self { Self { last_active_indices: BTreeMap::new(), graph: TxGraph::default(), - chain: Some(chain_update), + chain: None, } } } diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index 34c3928b..49692b5c 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -61,7 +61,7 @@ async fn main() -> Result<(), Box> { let update = WalletUpdate { last_active_indices, graph: update_graph, - ..WalletUpdate::new(chain_update) + chain: Some(chain_update), }; wallet.apply_update(update)?; wallet.commit()?; diff --git a/example-crates/wallet_esplora_blocking/src/main.rs b/example-crates/wallet_esplora_blocking/src/main.rs index 0fb6b4bd..fb6e0e87 100644 --- a/example-crates/wallet_esplora_blocking/src/main.rs +++ b/example-crates/wallet_esplora_blocking/src/main.rs @@ -60,7 +60,7 @@ fn main() -> Result<(), Box> { let update = WalletUpdate { last_active_indices, graph: update_graph, - ..WalletUpdate::new(chain_update) + chain: Some(chain_update), }; wallet.apply_update(update)?;