[wallet_redesign] Move the majority of Update
to bdk_chain
This is to make it easier for chain source crates to formulate updates.
This commit is contained in:
parent
e69fccb15f
commit
aba88130d9
@ -22,7 +22,7 @@ use alloc::{
|
||||
pub use bdk_chain::keychain::Balance;
|
||||
use bdk_chain::{
|
||||
indexed_tx_graph::{IndexedAdditions, IndexedTxGraph},
|
||||
keychain::{DerivationAdditions, KeychainTxOutIndex},
|
||||
keychain::{DerivationAdditions, KeychainTxOutIndex, LocalUpdate},
|
||||
local_chain::{self, LocalChain, UpdateNotConnectedError},
|
||||
tx_graph::{CanonicalTx, TxGraph},
|
||||
Anchor, Append, BlockId, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut, ObservedAs,
|
||||
@ -94,21 +94,14 @@ pub struct Wallet<D = ()> {
|
||||
}
|
||||
|
||||
/// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
|
||||
/// The type parameter `T` indicates the kind of transaction contained in the update. It's usually a [`bitcoin::Transaction`].
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct Update<K = KeychainKind, A = ConfirmationTimeAnchor> {
|
||||
keychain: BTreeMap<K, u32>,
|
||||
graph: TxGraph<A>,
|
||||
chain: LocalChain,
|
||||
}
|
||||
pub type Update = LocalUpdate<KeychainKind, ConfirmationTimeAnchor>;
|
||||
|
||||
/// The changeset produced internally by applying an update
|
||||
/// The changeset produced internally by applying an update.
|
||||
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(bound(
|
||||
deserialize = "A: Ord + serde::Deserialize<'de>, K: Ord + serde::Deserialize<'de>",
|
||||
serialize = "A: Ord + serde::Serialize, K: Ord + serde::Serialize"
|
||||
))]
|
||||
// #[cfg_attr(predicate, attr)]
|
||||
pub struct ChangeSet<K = KeychainKind, A = ConfirmationTimeAnchor> {
|
||||
pub chain_changeset: local_chain::ChangeSet,
|
||||
pub indexed_additions: IndexedAdditions<A, DerivationAdditions<K>>,
|
||||
|
@ -18,6 +18,7 @@
|
||||
use crate::{
|
||||
chain_graph::{self, ChainGraph},
|
||||
collections::BTreeMap,
|
||||
local_chain::LocalChain,
|
||||
sparse_chain::ChainPosition,
|
||||
tx_graph::TxGraph,
|
||||
Append, ForEachTxOut,
|
||||
@ -102,6 +103,28 @@ impl<K> AsRef<BTreeMap<K, u32>> for DerivationAdditions<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A structure to update [`KeychainTxOutIndex`], [`TxGraph`] and [`LocalChain`]
|
||||
/// atomically.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LocalUpdate<K, A> {
|
||||
/// Last active derivation index per keychain (`K`).
|
||||
pub keychain: BTreeMap<K, u32>,
|
||||
/// Update for the [`TxGraph`].
|
||||
pub graph: TxGraph<A>,
|
||||
/// Update for the [`LocalChain`].
|
||||
pub chain: LocalChain,
|
||||
}
|
||||
|
||||
impl<K, A> Default for LocalUpdate<K, A> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
keychain: Default::default(),
|
||||
graph: Default::default(),
|
||||
chain: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
/// An update that includes the last active indexes of each keychain.
|
||||
pub struct KeychainScan<K, P> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user