refactor: Move WalletUpdate to wallet module
This commit is contained in:
		
							parent
							
								
									7c12dc9942
								
							
						
					
					
						commit
						2392e50fd9
					
				| @ -22,7 +22,7 @@ use alloc::{ | ||||
| pub use bdk_chain::keychain::Balance; | ||||
| use bdk_chain::{ | ||||
|     indexed_tx_graph, | ||||
|     keychain::{KeychainTxOutIndex, WalletChangeSet, WalletUpdate}, | ||||
|     keychain::{KeychainTxOutIndex, WalletChangeSet}, | ||||
|     local_chain::{self, CannotConnectError, CheckPoint, CheckPointIter, LocalChain}, | ||||
|     tx_graph::{CanonicalTx, TxGraph}, | ||||
|     Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut, | ||||
| @ -95,6 +95,35 @@ pub struct Wallet<D = ()> { | ||||
|     secp: SecpCtx, | ||||
| } | ||||
| 
 | ||||
| /// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
 | ||||
| ///
 | ||||
| /// [`LocalChain`]: local_chain::LocalChain
 | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct WalletUpdate<K, A> { | ||||
|     /// Contains the last active derivation indices per keychain (`K`), which is used to update the
 | ||||
|     /// [`KeychainTxOutIndex`].
 | ||||
|     pub last_active_indices: BTreeMap<K, u32>, | ||||
| 
 | ||||
|     /// Update for the [`TxGraph`].
 | ||||
|     pub graph: TxGraph<A>, | ||||
| 
 | ||||
|     /// Update for the [`LocalChain`].
 | ||||
|     ///
 | ||||
|     /// [`LocalChain`]: local_chain::LocalChain
 | ||||
|     pub chain: local_chain::Update, | ||||
| } | ||||
| 
 | ||||
| impl<K, A> WalletUpdate<K, A> { | ||||
|     /// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
 | ||||
|     pub fn new(chain_update: local_chain::Update) -> Self { | ||||
|         Self { | ||||
|             last_active_indices: BTreeMap::new(), | ||||
|             graph: TxGraph::default(), | ||||
|             chain: chain_update, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
 | ||||
| pub type Update = WalletUpdate<KeychainKind, ConfirmationTimeAnchor>; | ||||
| 
 | ||||
|  | ||||
| @ -10,9 +10,7 @@ | ||||
| //!
 | ||||
| //! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
 | ||||
| 
 | ||||
| use crate::{ | ||||
|     collections::BTreeMap, indexed_tx_graph, local_chain, tx_graph::TxGraph, Anchor, Append, | ||||
| }; | ||||
| use crate::{collections::BTreeMap, indexed_tx_graph, local_chain, Anchor, Append}; | ||||
| 
 | ||||
| #[cfg(feature = "miniscript")] | ||||
| mod txout_index; | ||||
| @ -82,35 +80,6 @@ impl<K> AsRef<BTreeMap<K, u32>> for ChangeSet<K> { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
 | ||||
| ///
 | ||||
| /// [`LocalChain`]: local_chain::LocalChain
 | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct WalletUpdate<K, A> { | ||||
|     /// Contains the last active derivation indices per keychain (`K`), which is used to update the
 | ||||
|     /// [`KeychainTxOutIndex`].
 | ||||
|     pub last_active_indices: BTreeMap<K, u32>, | ||||
| 
 | ||||
|     /// Update for the [`TxGraph`].
 | ||||
|     pub graph: TxGraph<A>, | ||||
| 
 | ||||
|     /// Update for the [`LocalChain`].
 | ||||
|     ///
 | ||||
|     /// [`LocalChain`]: local_chain::LocalChain
 | ||||
|     pub chain: local_chain::Update, | ||||
| } | ||||
| 
 | ||||
| impl<K, A> WalletUpdate<K, A> { | ||||
|     /// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
 | ||||
|     pub fn new(chain_update: local_chain::Update) -> Self { | ||||
|         Self { | ||||
|             last_active_indices: BTreeMap::new(), | ||||
|             graph: TxGraph::default(), | ||||
|             chain: chain_update, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// A structure that records the corresponding changes as result of applying an [`WalletUpdate`].
 | ||||
| #[derive(Debug, Clone, PartialEq)] | ||||
| #[cfg_attr(
 | ||||
|  | ||||
| @ -8,8 +8,8 @@ use std::str::FromStr; | ||||
| 
 | ||||
| use bdk::bitcoin::Address; | ||||
| use bdk::SignOptions; | ||||
| use bdk::{bitcoin::Network, Wallet}; | ||||
| use bdk_electrum::bdk_chain::{keychain::WalletUpdate, local_chain}; | ||||
| use bdk::{bitcoin::Network, wallet::WalletUpdate, Wallet}; | ||||
| use bdk_electrum::bdk_chain::local_chain; | ||||
| use bdk_electrum::electrum_client::{self, ElectrumApi}; | ||||
| use bdk_electrum::ElectrumExt; | ||||
| use bdk_file_store::Store; | ||||
|  | ||||
| @ -2,8 +2,7 @@ use std::{io::Write, str::FromStr}; | ||||
| 
 | ||||
| use bdk::{ | ||||
|     bitcoin::{Address, Network}, | ||||
|     chain::keychain::WalletUpdate, | ||||
|     wallet::AddressIndex, | ||||
|     wallet::{AddressIndex, WalletUpdate}, | ||||
|     SignOptions, Wallet, | ||||
| }; | ||||
| use bdk_esplora::{esplora_client, EsploraAsyncExt}; | ||||
|  | ||||
| @ -7,8 +7,7 @@ use std::{io::Write, str::FromStr}; | ||||
| 
 | ||||
| use bdk::{ | ||||
|     bitcoin::{Address, Network}, | ||||
|     chain::keychain::WalletUpdate, | ||||
|     wallet::AddressIndex, | ||||
|     wallet::{AddressIndex, WalletUpdate}, | ||||
|     SignOptions, Wallet, | ||||
| }; | ||||
| use bdk_esplora::{esplora_client, EsploraExt}; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user