Skip to content

Commit f96fca2

Browse files
vladimirfomeneevanlinjin
authored andcommitted
refactor: Move WalletUpdate to wallet module
1 parent d308a61 commit f96fca2

File tree

5 files changed

+35
-39
lines changed

5 files changed

+35
-39
lines changed

crates/bdk/src/wallet/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use alloc::{
2222
pub use bdk_chain::keychain::Balance;
2323
use bdk_chain::{
2424
indexed_tx_graph,
25-
keychain::{KeychainTxOutIndex, WalletChangeSet, WalletUpdate},
25+
keychain::{KeychainTxOutIndex, WalletChangeSet},
2626
local_chain::{self, CannotConnectError, CheckPoint, CheckPointIter, LocalChain},
2727
tx_graph::{CanonicalTx, TxGraph},
2828
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut,
@@ -94,6 +94,35 @@ pub struct Wallet<D = ()> {
9494
secp: SecpCtx,
9595
}
9696

97+
/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
98+
///
99+
/// [`LocalChain`]: local_chain::LocalChain
100+
#[derive(Debug, Clone)]
101+
pub struct WalletUpdate<K, A> {
102+
/// Contains the last active derivation indices per keychain (`K`), which is used to update the
103+
/// [`KeychainTxOutIndex`].
104+
pub last_active_indices: BTreeMap<K, u32>,
105+
106+
/// Update for the [`TxGraph`].
107+
pub graph: TxGraph<A>,
108+
109+
/// Update for the [`LocalChain`].
110+
///
111+
/// [`LocalChain`]: local_chain::LocalChain
112+
pub chain: local_chain::Update,
113+
}
114+
115+
impl<K, A> WalletUpdate<K, A> {
116+
/// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
117+
pub fn new(chain_update: local_chain::Update) -> Self {
118+
Self {
119+
last_active_indices: BTreeMap::new(),
120+
graph: TxGraph::default(),
121+
chain: chain_update,
122+
}
123+
}
124+
}
125+
97126
/// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
98127
pub type Update = WalletUpdate<KeychainKind, ConfirmationTimeAnchor>;
99128

crates/chain/src/keychain.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
//!
1111
//! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
1212
13-
use crate::{
14-
collections::BTreeMap, indexed_tx_graph, local_chain, tx_graph::TxGraph, Anchor, Append,
15-
};
13+
use crate::{collections::BTreeMap, indexed_tx_graph, local_chain, Anchor, Append};
1614

1715
#[cfg(feature = "miniscript")]
1816
mod txout_index;
@@ -82,35 +80,6 @@ impl<K> AsRef<BTreeMap<K, u32>> for ChangeSet<K> {
8280
}
8381
}
8482

85-
/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
86-
///
87-
/// [`LocalChain`]: local_chain::LocalChain
88-
#[derive(Debug, Clone)]
89-
pub struct WalletUpdate<K, A> {
90-
/// Contains the last active derivation indices per keychain (`K`), which is used to update the
91-
/// [`KeychainTxOutIndex`].
92-
pub last_active_indices: BTreeMap<K, u32>,
93-
94-
/// Update for the [`TxGraph`].
95-
pub graph: TxGraph<A>,
96-
97-
/// Update for the [`LocalChain`].
98-
///
99-
/// [`LocalChain`]: local_chain::LocalChain
100-
pub chain: local_chain::Update,
101-
}
102-
103-
impl<K, A> WalletUpdate<K, A> {
104-
/// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
105-
pub fn new(chain_update: local_chain::Update) -> Self {
106-
Self {
107-
last_active_indices: BTreeMap::new(),
108-
graph: TxGraph::default(),
109-
chain: chain_update,
110-
}
111-
}
112-
}
113-
11483
/// A structure that records the corresponding changes as result of applying an [`WalletUpdate`].
11584
#[derive(Debug, Clone, PartialEq)]
11685
#[cfg_attr(

example-crates/wallet_electrum/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::str::FromStr;
88

99
use bdk::bitcoin::Address;
1010
use bdk::SignOptions;
11-
use bdk::{bitcoin::Network, Wallet};
12-
use bdk_electrum::bdk_chain::{keychain::WalletUpdate, local_chain};
11+
use bdk::{bitcoin::Network, wallet::WalletUpdate, Wallet};
12+
use bdk_electrum::bdk_chain::local_chain;
1313
use bdk_electrum::electrum_client::{self, ElectrumApi};
1414
use bdk_electrum::ElectrumExt;
1515
use bdk_file_store::Store;

example-crates/wallet_esplora_async/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use std::{io::Write, str::FromStr};
22

33
use bdk::{
44
bitcoin::{Address, Network},
5-
chain::keychain::WalletUpdate,
6-
wallet::AddressIndex,
5+
wallet::{AddressIndex, WalletUpdate},
76
SignOptions, Wallet,
87
};
98
use bdk_esplora::{esplora_client, EsploraAsyncExt};

example-crates/wallet_esplora_blocking/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use std::{io::Write, str::FromStr};
77

88
use bdk::{
99
bitcoin::{Address, Network},
10-
chain::keychain::WalletUpdate,
11-
wallet::AddressIndex,
10+
wallet::{AddressIndex, WalletUpdate},
1211
SignOptions, Wallet,
1312
};
1413
use bdk_esplora::{esplora_client, EsploraExt};

0 commit comments

Comments
 (0)