refactor: Implement Default for WalletUpdate
This commit is contained in:
parent
f42f8b8ff1
commit
a28748c339
@ -95,9 +95,9 @@ pub struct Wallet<D = ()> {
|
|||||||
secp: SecpCtx,
|
secp: SecpCtx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`] atomically.
|
/// A structure to update [`Wallet`].
|
||||||
///
|
///
|
||||||
/// [`LocalChain`]: local_chain::LocalChain
|
/// It updates [`bdk_chain::keychain::KeychainTxOutIndex`], [`bdk_chain::TxGraph`] and [`local_chain::LocalChain`] atomically.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct WalletUpdate<K, A> {
|
pub struct WalletUpdate<K, A> {
|
||||||
/// Contains the last active derivation indices per keychain (`K`), which is used to update the
|
/// Contains the last active derivation indices per keychain (`K`), which is used to update the
|
||||||
@ -113,13 +113,12 @@ pub struct WalletUpdate<K, A> {
|
|||||||
pub chain: Option<local_chain::Update>,
|
pub chain: Option<local_chain::Update>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K, A> WalletUpdate<K, A> {
|
impl<K, A> Default for WalletUpdate<K, A> {
|
||||||
/// Construct a [`WalletUpdate`] with a given [`local_chain::Update`].
|
fn default() -> Self {
|
||||||
pub fn new(chain_update: local_chain::Update) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
last_active_indices: BTreeMap::new(),
|
last_active_indices: BTreeMap::new(),
|
||||||
graph: TxGraph::default(),
|
graph: TxGraph::default(),
|
||||||
chain: Some(chain_update),
|
chain: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let update = WalletUpdate {
|
let update = WalletUpdate {
|
||||||
last_active_indices,
|
last_active_indices,
|
||||||
graph: update_graph,
|
graph: update_graph,
|
||||||
..WalletUpdate::new(chain_update)
|
chain: Some(chain_update),
|
||||||
};
|
};
|
||||||
wallet.apply_update(update)?;
|
wallet.apply_update(update)?;
|
||||||
wallet.commit()?;
|
wallet.commit()?;
|
||||||
|
@ -60,7 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let update = WalletUpdate {
|
let update = WalletUpdate {
|
||||||
last_active_indices,
|
last_active_indices,
|
||||||
graph: update_graph,
|
graph: update_graph,
|
||||||
..WalletUpdate::new(chain_update)
|
chain: Some(chain_update),
|
||||||
};
|
};
|
||||||
|
|
||||||
wallet.apply_update(update)?;
|
wallet.apply_update(update)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user