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,
}
/// 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>>,
use crate::{
chain_graph::{self, ChainGraph},
collections::BTreeMap,
+ local_chain::LocalChain,
sparse_chain::ChainPosition,
tx_graph::TxGraph,
Append, ForEachTxOut,
}
}
+/// 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> {