@@ -25,7 +25,7 @@ use bdk_chain::{
2525 keychain:: { self , KeychainTxOutIndex } ,
2626 local_chain:: { self , CannotConnectError , CheckPoint , CheckPointIter , LocalChain } ,
2727 tx_graph:: { CanonicalTx , TxGraph } ,
28- Anchor , Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
28+ Append , BlockId , ChainPosition , ConfirmationTime , ConfirmationTimeAnchor , FullTxOut ,
2929 IndexedTxGraph , Persist , PersistBackend ,
3030} ;
3131use bitcoin:: consensus:: encode:: serialize;
@@ -95,73 +95,51 @@ pub struct Wallet<D = ()> {
9595 secp : SecpCtx ,
9696}
9797
98- /// A structure to update [`Wallet`].
98+ /// An update to [`Wallet`].
9999///
100100/// 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 {
103103 /// Contains the last active derivation indices per keychain (`K`), which is used to update the
104104 /// [`KeychainTxOutIndex`].
105- pub last_active_indices : BTreeMap < K , u32 > ,
105+ pub last_active_indices : BTreeMap < KeychainKind , u32 > ,
106106
107- /// Update for the [`TxGraph`].
108- pub graph : TxGraph < A > ,
107+ /// Update for the wallet's internal [`TxGraph`].
108+ pub graph : TxGraph < ConfirmationTimeAnchor > ,
109109
110- /// Update for the [`LocalChain`].
110+ /// Update for the wallet's internal [`LocalChain`].
111111 ///
112112 /// [`LocalChain`]: local_chain::LocalChain
113113 pub chain : Option < local_chain:: Update > ,
114114}
115115
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 {
129119 /// Changes to the [`LocalChain`].
130120 ///
131121 /// [`LocalChain`]: local_chain::LocalChain
132122 pub chain : local_chain:: ChangeSet ,
133123
134- /// ChangeSet to [`IndexedTxGraph`].
124+ /// Changes to [`IndexedTxGraph`].
135125 ///
136126 /// [`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 > > ,
142129}
143130
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 {
154132 fn append ( & mut self , other : Self ) {
155133 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 ) ;
157135 }
158136
159137 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 ( )
161139 }
162140}
163141
164- impl < K , A > From < local_chain:: ChangeSet > for WalletChangeSet < K , A > {
142+ impl From < local_chain:: ChangeSet > for ChangeSet {
165143 fn from ( chain : local_chain:: ChangeSet ) -> Self {
166144 Self {
167145 chain,
@@ -170,21 +148,22 @@ impl<K, A> From<local_chain::ChangeSet> for WalletChangeSet<K, A> {
170148 }
171149}
172150
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 {
175160 Self {
176- index_tx_graph ,
161+ indexed_tx_graph ,
177162 ..Default :: default ( )
178163 }
179164 }
180165}
181166
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-
188167/// The address index selection strategy to use to derived an address from the wallet's external
189168/// descriptor. See [`Wallet::get_address`]. If you're unsure which one to use use `WalletIndex::New`.
190169#[ derive( Debug ) ]
@@ -332,7 +311,7 @@ impl<D> Wallet<D> {
332311
333312 let changeset = db. load_from_persistence ( ) . map_err ( NewError :: Persist ) ?;
334313 chain. apply_changeset ( & changeset. chain ) ;
335- indexed_graph. apply_changeset ( changeset. index_tx_graph ) ;
314+ indexed_graph. apply_changeset ( changeset. indexed_tx_graph ) ;
336315
337316 let persist = Persist :: new ( db) ;
338317
0 commit comments