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