]> Untitled Git - bdk/commitdiff
refactor: Allow for no chain update
authorVladimir Fomene <vladimirfomene@gmail.com>
Thu, 24 Aug 2023 13:03:47 +0000 (16:03 +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_electrum/src/main.rs

index 47dd03de201dba3f6656f3aa99eef42b68c0ca46..21ba5ee6da1759a742f85f613b09bf74a4fbcf4b 100644 (file)
@@ -110,7 +110,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> {
@@ -119,7 +119,7 @@ impl<K, A> WalletUpdate<K, A> {
         Self {
             last_active_indices: BTreeMap::new(),
             graph: TxGraph::default(),
-            chain: chain_update,
+            chain: Some(chain_update),
         }
     }
 }
@@ -1942,7 +1942,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
index 86ea8a7c28bfd86bbeb547600652f63f2e4c6040..0ea7df486435d011c39af30788b55443ccd1359d 100644 (file)
@@ -64,10 +64,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
     let wallet_update = WalletUpdate {
         last_active_indices: keychain_update,
         graph: graph_update,
-        chain: local_chain::Update {
+        chain: Some(local_chain::Update {
             tip: update_tip,
             introduce_older_blocks: true,
-        },
+        }),
     };
     wallet.apply_update(wallet_update)?;
     wallet.commit()?;