]> Untitled Git - bdk/commitdiff
refactor: Implement Default for WalletUpdate
authorVladimir Fomene <vladimirfomene@gmail.com>
Fri, 25 Aug 2023 09:49:29 +0000 (12:49 +0300)
committer志宇 <hello@evanlinjin.me>
Sat, 2 Sep 2023 17:51:20 +0000 (01:51 +0800)
crates/bdk/src/wallet/mod.rs
example-crates/wallet_esplora_async/src/main.rs
example-crates/wallet_esplora_blocking/src/main.rs

index 21ba5ee6da1759a742f85f613b09bf74a4fbcf4b..a7fe4d42a6ad339df329f7af2b22373f566f2797 100644 (file)
@@ -95,9 +95,9 @@ pub struct Wallet<D = ()> {
     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<K, A> {
     /// Contains the last active derivation indices per keychain (`K`), which is used to update the
@@ -113,13 +113,12 @@ pub struct WalletUpdate<K, A> {
     pub chain: Option<local_chain::Update>,
 }
 
-impl<K, A> WalletUpdate<K, A> {
-    /// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
-    pub fn new(chain_update: local_chain::Update) -> Self {
+impl<K, A> Default for WalletUpdate<K, A> {
+    fn default() -> Self {
         Self {
             last_active_indices: BTreeMap::new(),
             graph: TxGraph::default(),
-            chain: Some(chain_update),
+            chain: None,
         }
     }
 }
index 34c3928b8e2144434d19c8288a72a629c2b38492..49692b5cb2dafdb5591436f54f199ca10f6ecb6c 100644 (file)
@@ -61,7 +61,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
     let update = WalletUpdate {
         last_active_indices,
         graph: update_graph,
-        ..WalletUpdate::new(chain_update)
+        chain: Some(chain_update),
     };
     wallet.apply_update(update)?;
     wallet.commit()?;
index 0fb6b4bd6e7c72a4d38d33b29ef919a506262dfb..fb6e0e8778d997dbbf141ef6dced612d7e7ceec4 100644 (file)
@@ -60,7 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
     let update = WalletUpdate {
         last_active_indices,
         graph: update_graph,
-        ..WalletUpdate::new(chain_update)
+        chain: Some(chain_update),
     };
 
     wallet.apply_update(update)?;