]> Untitled Git - bdk/commitdiff
refactor: Move WalletUpdate to wallet module
authorVladimir Fomene <vladimirfomene@gmail.com>
Mon, 21 Aug 2023 09:13:58 +0000 (12:13 +0300)
committer志宇 <hello@evanlinjin.me>
Sat, 2 Sep 2023 16:54:23 +0000 (00:54 +0800)
crates/bdk/src/wallet/mod.rs
crates/chain/src/keychain.rs
example-crates/wallet_electrum/src/main.rs
example-crates/wallet_esplora_async/src/main.rs
example-crates/wallet_esplora_blocking/src/main.rs

index f7bc5f49b9a12d196233f42f59636453a9ab7f19..1fe16147a8b31b873d6c9b71f581aa987eb28f24 100644 (file)
@@ -22,7 +22,7 @@ use alloc::{
 pub use bdk_chain::keychain::Balance;
 use bdk_chain::{
     indexed_tx_graph,
-    keychain::{KeychainTxOutIndex, WalletChangeSet, WalletUpdate},
+    keychain::{KeychainTxOutIndex, WalletChangeSet},
     local_chain::{self, CannotConnectError, CheckPoint, CheckPointIter, LocalChain},
     tx_graph::{CanonicalTx, TxGraph},
     Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut,
@@ -95,6 +95,35 @@ pub struct Wallet<D = ()> {
     secp: SecpCtx,
 }
 
+/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
+///
+/// [`LocalChain`]: local_chain::LocalChain
+#[derive(Debug, Clone)]
+pub struct WalletUpdate<K, A> {
+    /// Contains the last active derivation indices per keychain (`K`), which is used to update the
+    /// [`KeychainTxOutIndex`].
+    pub last_active_indices: BTreeMap<K, u32>,
+
+    /// Update for the [`TxGraph`].
+    pub graph: TxGraph<A>,
+
+    /// Update for the [`LocalChain`].
+    ///
+    /// [`LocalChain`]: local_chain::LocalChain
+    pub chain: 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 {
+        Self {
+            last_active_indices: BTreeMap::new(),
+            graph: TxGraph::default(),
+            chain: chain_update,
+        }
+    }
+}
+
 /// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
 pub type Update = WalletUpdate<KeychainKind, ConfirmationTimeAnchor>;
 
index 3a6cddf80ff92b16344efd5a5412e9cce1795867..74e982429f153c2030c65bdcacbd860dda821a40 100644 (file)
@@ -10,9 +10,7 @@
 //!
 //! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
 
-use crate::{
-    collections::BTreeMap, indexed_tx_graph, local_chain, tx_graph::TxGraph, Anchor, Append,
-};
+use crate::{collections::BTreeMap, indexed_tx_graph, local_chain, Anchor, Append};
 
 #[cfg(feature = "miniscript")]
 mod txout_index;
@@ -82,35 +80,6 @@ impl<K> AsRef<BTreeMap<K, u32>> for ChangeSet<K> {
     }
 }
 
-/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
-///
-/// [`LocalChain`]: local_chain::LocalChain
-#[derive(Debug, Clone)]
-pub struct WalletUpdate<K, A> {
-    /// Contains the last active derivation indices per keychain (`K`), which is used to update the
-    /// [`KeychainTxOutIndex`].
-    pub last_active_indices: BTreeMap<K, u32>,
-
-    /// Update for the [`TxGraph`].
-    pub graph: TxGraph<A>,
-
-    /// Update for the [`LocalChain`].
-    ///
-    /// [`LocalChain`]: local_chain::LocalChain
-    pub chain: 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 {
-        Self {
-            last_active_indices: BTreeMap::new(),
-            graph: TxGraph::default(),
-            chain: chain_update,
-        }
-    }
-}
-
 /// A structure that records the corresponding changes as result of applying an [`WalletUpdate`].
 #[derive(Debug, Clone, PartialEq)]
 #[cfg_attr(
index 3ba7e5f4c1592d25f7337870ab45257c02f04970..86ea8a7c28bfd86bbeb547600652f63f2e4c6040 100644 (file)
@@ -8,8 +8,8 @@ use std::str::FromStr;
 
 use bdk::bitcoin::Address;
 use bdk::SignOptions;
-use bdk::{bitcoin::Network, Wallet};
-use bdk_electrum::bdk_chain::{keychain::WalletUpdate, local_chain};
+use bdk::{bitcoin::Network, wallet::WalletUpdate, Wallet};
+use bdk_electrum::bdk_chain::local_chain;
 use bdk_electrum::electrum_client::{self, ElectrumApi};
 use bdk_electrum::ElectrumExt;
 use bdk_file_store::Store;
index 343a09763fd5f0486849450e510a8c727b7b79cb..34c3928b8e2144434d19c8288a72a629c2b38492 100644 (file)
@@ -2,8 +2,7 @@ use std::{io::Write, str::FromStr};
 
 use bdk::{
     bitcoin::{Address, Network},
-    chain::keychain::WalletUpdate,
-    wallet::AddressIndex,
+    wallet::{AddressIndex, WalletUpdate},
     SignOptions, Wallet,
 };
 use bdk_esplora::{esplora_client, EsploraAsyncExt};
index d108742a5312ebdb9fba6af01ca44b70ad59e936..0fb6b4bd6e7c72a4d38d33b29ef919a506262dfb 100644 (file)
@@ -7,8 +7,7 @@ use std::{io::Write, str::FromStr};
 
 use bdk::{
     bitcoin::{Address, Network},
-    chain::keychain::WalletUpdate,
-    wallet::AddressIndex,
+    wallet::{AddressIndex, WalletUpdate},
     SignOptions, Wallet,
 };
 use bdk_esplora::{esplora_client, EsploraExt};