@@ -25,7 +25,7 @@ use bdk_chain::{
25
25
keychain:: { self , KeychainTxOutIndex } ,
26
26
local_chain:: { self , CannotConnectError , CheckPoint , CheckPointIter , LocalChain } ,
27
27
tx_graph:: { CanonicalTx , TxGraph } ,
28
- Anchor , Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
28
+ Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
29
29
IndexedTxGraph , Persist , PersistBackend ,
30
30
} ;
31
31
use bitcoin:: consensus:: encode:: serialize;
@@ -95,73 +95,51 @@ pub struct Wallet<D = ()> {
95
95
secp : SecpCtx ,
96
96
}
97
97
98
- /// A structure to update [`Wallet`].
98
+ /// An update to [`Wallet`].
99
99
///
100
100
/// It updates [`bdk_chain::keychain::KeychainTxOutIndex`], [`bdk_chain::TxGraph`] and [`local_chain::LocalChain`] atomically.
101
- #[ derive( Debug , Clone ) ]
102
- pub struct WalletUpdate < K , A > {
101
+ #[ derive( Debug , Clone , Default ) ]
102
+ pub struct Update {
103
103
/// Contains the last active derivation indices per keychain (`K`), which is used to update the
104
104
/// [`KeychainTxOutIndex`].
105
- pub last_active_indices : BTreeMap < K , u32 > ,
105
+ pub last_active_indices : BTreeMap < KeychainKind , u32 > ,
106
106
107
- /// Update for the [`TxGraph`].
108
- pub graph : TxGraph < A > ,
107
+ /// Update for the wallet's internal [`TxGraph`].
108
+ pub graph : TxGraph < ConfirmationTimeAnchor > ,
109
109
110
- /// Update for the [`LocalChain`].
110
+ /// Update for the wallet's internal [`LocalChain`].
111
111
///
112
112
/// [`LocalChain`]: local_chain::LocalChain
113
113
pub chain : Option < local_chain:: Update > ,
114
114
}
115
115
116
- impl < K , A > Default for WalletUpdate < K , A > {
117
- fn default ( ) -> Self {
118
- Self {
119
- last_active_indices : BTreeMap :: new ( ) ,
120
- graph : TxGraph :: default ( ) ,
121
- chain : None ,
122
- }
123
- }
124
- }
125
-
126
- /// A structure that records the corresponding changes as result of applying an [`WalletUpdate`].
127
- #[ derive( Debug , Clone , PartialEq , serde:: Serialize , serde:: Deserialize ) ]
128
- pub struct WalletChangeSet < K , A > {
116
+ /// The changes made to a wallet by applying an [`Update`].
117
+ #[ derive( Debug , Clone , PartialEq , serde:: Serialize , serde:: Deserialize , Default ) ]
118
+ pub struct ChangeSet {
129
119
/// Changes to the [`LocalChain`].
130
120
///
131
121
/// [`LocalChain`]: local_chain::LocalChain
132
122
pub chain : local_chain:: ChangeSet ,
133
123
134
- /// ChangeSet to [`IndexedTxGraph`].
124
+ /// Changes to [`IndexedTxGraph`].
135
125
///
136
126
/// [`IndexedTxGraph`]: bdk_chain::indexed_tx_graph::IndexedTxGraph
137
- #[ serde( bound(
138
- deserialize = "K: Ord + serde::Deserialize<'de>, A: Ord + serde::Deserialize<'de>" ,
139
- serialize = "K: Ord + serde::Serialize, A: Ord + serde::Serialize" ,
140
- ) ) ]
141
- pub index_tx_graph : indexed_tx_graph:: ChangeSet < A , keychain:: ChangeSet < K > > ,
127
+ pub indexed_tx_graph :
128
+ indexed_tx_graph:: ChangeSet < ConfirmationTimeAnchor , keychain:: ChangeSet < KeychainKind > > ,
142
129
}
143
130
144
- impl < K , A > Default for WalletChangeSet < K , A > {
145
- fn default ( ) -> Self {
146
- Self {
147
- chain : Default :: default ( ) ,
148
- index_tx_graph : Default :: default ( ) ,
149
- }
150
- }
151
- }
152
-
153
- impl < K : Ord , A : Anchor > Append for WalletChangeSet < K , A > {
131
+ impl Append for ChangeSet {
154
132
fn append ( & mut self , other : Self ) {
155
133
Append :: append ( & mut self . chain , other. chain ) ;
156
- Append :: append ( & mut self . index_tx_graph , other. index_tx_graph ) ;
134
+ Append :: append ( & mut self . indexed_tx_graph , other. indexed_tx_graph ) ;
157
135
}
158
136
159
137
fn is_empty ( & self ) -> bool {
160
- self . chain . is_empty ( ) && self . index_tx_graph . is_empty ( )
138
+ self . chain . is_empty ( ) && self . indexed_tx_graph . is_empty ( )
161
139
}
162
140
}
163
141
164
- impl < K , A > From < local_chain:: ChangeSet > for WalletChangeSet < K , A > {
142
+ impl From < local_chain:: ChangeSet > for ChangeSet {
165
143
fn from ( chain : local_chain:: ChangeSet ) -> Self {
166
144
Self {
167
145
chain,
@@ -170,21 +148,22 @@ impl<K, A> From<local_chain::ChangeSet> for WalletChangeSet<K, A> {
170
148
}
171
149
}
172
150
173
- impl < K , A > From < indexed_tx_graph:: ChangeSet < A , keychain:: ChangeSet < K > > > for WalletChangeSet < K , A > {
174
- fn from ( index_tx_graph : indexed_tx_graph:: ChangeSet < A , keychain:: ChangeSet < K > > ) -> Self {
151
+ impl From < indexed_tx_graph:: ChangeSet < ConfirmationTimeAnchor , keychain:: ChangeSet < KeychainKind > > >
152
+ for ChangeSet
153
+ {
154
+ fn from (
155
+ indexed_tx_graph : indexed_tx_graph:: ChangeSet <
156
+ ConfirmationTimeAnchor ,
157
+ keychain:: ChangeSet < KeychainKind > ,
158
+ > ,
159
+ ) -> Self {
175
160
Self {
176
- index_tx_graph ,
161
+ indexed_tx_graph ,
177
162
..Default :: default ( )
178
163
}
179
164
}
180
165
}
181
166
182
- /// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
183
- pub type Update = WalletUpdate < KeychainKind , ConfirmationTimeAnchor > ;
184
-
185
- /// The changeset produced internally by [`Wallet`] when mutated.
186
- pub type ChangeSet = WalletChangeSet < KeychainKind , ConfirmationTimeAnchor > ;
187
-
188
167
/// The address index selection strategy to use to derived an address from the wallet's external
189
168
/// descriptor. See [`Wallet::get_address`]. If you're unsure which one to use use `WalletIndex::New`.
190
169
#[ derive( Debug ) ]
@@ -332,7 +311,7 @@ impl<D> Wallet<D> {
332
311
333
312
let changeset = db. load_from_persistence ( ) . map_err ( NewError :: Persist ) ?;
334
313
chain. apply_changeset ( & changeset. chain ) ;
335
- indexed_graph. apply_changeset ( changeset. index_tx_graph ) ;
314
+ indexed_graph. apply_changeset ( changeset. indexed_tx_graph ) ;
336
315
337
316
let persist = Persist :: new ( db) ;
338
317
0 commit comments