@@ -22,7 +22,7 @@ use alloc::{
2222pub use bdk_chain:: keychain:: Balance ;
2323use 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.
98127pub type Update = WalletUpdate < KeychainKind , ConfirmationTimeAnchor > ;
99128
0 commit comments