diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 1ca78a7759..7b0ca56a91 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -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, @@ -94,6 +94,35 @@ pub struct Wallet { secp: SecpCtx, } +/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically. +/// +/// [`LocalChain`]: local_chain::LocalChain +#[derive(Debug, Clone)] +pub struct WalletUpdate { + /// Contains the last active derivation indices per keychain (`K`), which is used to update the + /// [`KeychainTxOutIndex`]. + pub last_active_indices: BTreeMap, + + /// Update for the [`TxGraph`]. + pub graph: TxGraph, + + /// Update for the [`LocalChain`]. + /// + /// [`LocalChain`]: local_chain::LocalChain + pub chain: local_chain::Update, +} + +impl WalletUpdate { + /// 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; diff --git a/crates/chain/src/keychain.rs b/crates/chain/src/keychain.rs index 64d68d81e9..b1f9c6f92b 100644 --- a/crates/chain/src/keychain.rs +++ b/crates/chain/src/keychain.rs @@ -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 AsRef> for ChangeSet { } } -/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically. -/// -/// [`LocalChain`]: local_chain::LocalChain -#[derive(Debug, Clone)] -pub struct WalletUpdate { - /// Contains the last active derivation indices per keychain (`K`), which is used to update the - /// [`KeychainTxOutIndex`]. - pub last_active_indices: BTreeMap, - - /// Update for the [`TxGraph`]. - pub graph: TxGraph, - - /// Update for the [`LocalChain`]. - /// - /// [`LocalChain`]: local_chain::LocalChain - pub chain: local_chain::Update, -} - -impl WalletUpdate { - /// 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( diff --git a/example-crates/wallet_electrum/src/main.rs b/example-crates/wallet_electrum/src/main.rs index 06da0ac32b..878c0abf40 100644 --- a/example-crates/wallet_electrum/src/main.rs +++ b/example-crates/wallet_electrum/src/main.rs @@ -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; diff --git a/example-crates/wallet_esplora/src/main.rs b/example-crates/wallet_esplora/src/main.rs index a9691f3676..45bdf189bc 100644 --- a/example-crates/wallet_esplora/src/main.rs +++ b/example-crates/wallet_esplora/src/main.rs @@ -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}; diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index 76e4b4506a..71b3a1a648 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -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};