Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce tx_graph::Update and simplify TxGraph update logic #1568

Merged
merged 6 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions crates/chain/src/indexed_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,36 @@ where

/// Apply an `update` directly.
///
/// `update` is a [`TxGraph<A>`] and the resultant changes is returned as [`ChangeSet`].
pub fn apply_update(&mut self, update: TxGraph<A>) -> ChangeSet<A, I::ChangeSet> {
let graph = self.graph.apply_update(update);
let indexer = self.index_tx_graph_changeset(&graph);
ChangeSet {
tx_graph: graph,
indexer,
}
/// `update` is a [`tx_graph::Update<A>`] and the resultant changes is returned as [`ChangeSet`].
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn apply_update(&mut self, update: tx_graph::Update<A>) -> ChangeSet<A, I::ChangeSet> {
let tx_graph = self.graph.apply_update(update);
let indexer = self.index_tx_graph_changeset(&tx_graph);
ChangeSet { tx_graph, indexer }
}

/// Apply the given `update` with an optional `seen_at` timestamp.
///
/// `seen_at` represents when the update is seen (in unix seconds). It is used to determine the
/// `last_seen`s for all transactions in the update which have no corresponding anchor(s). The
/// `last_seen` value is used internally to determine precedence of conflicting unconfirmed
/// transactions (where the transaction with the lower `last_seen` value is omitted from the
/// canonical history).
///
/// Not setting a `seen_at` value means unconfirmed transactions introduced by this update will
/// not be part of the canonical history of transactions.
///
/// Use [`apply_update`](IndexedTxGraph::apply_update) to have the `seen_at` value automatically
/// set to the current time.
pub fn apply_update_at(
&mut self,
update: tx_graph::Update<A>,
seen_at: Option<u64>,
) -> ChangeSet<A, I::ChangeSet> {
let tx_graph = self.graph.apply_update_at(update, seen_at);
let indexer = self.index_tx_graph_changeset(&tx_graph);
ChangeSet { tx_graph, indexer }
}

/// Insert a floating `txout` of given `outpoint`.
Expand Down
6 changes: 6 additions & 0 deletions crates/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
//!
//! [Bitcoin Dev Kit]: https://bitcoindevkit.org/

// only enables the `doc_cfg` feature when the `docsrs` configuration attribute is defined
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(
docsrs,
doc(html_logo_url = "https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png")
)]
#![no_std]
#![warn(missing_docs)]

Expand Down
10 changes: 5 additions & 5 deletions crates/chain/src/spk_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
alloc::{boxed::Box, collections::VecDeque, vec::Vec},
collections::BTreeMap,
local_chain::CheckPoint,
ConfirmationBlockTime, Indexed, TxGraph,
ConfirmationBlockTime, Indexed,
};
use bitcoin::{OutPoint, Script, ScriptBuf, Txid};

Expand Down Expand Up @@ -345,8 +345,8 @@ impl<I> SyncRequest<I> {
#[must_use]
#[derive(Debug)]
pub struct SyncResult<A = ConfirmationBlockTime> {
/// The update to apply to the receiving [`TxGraph`].
pub graph_update: TxGraph<A>,
/// The update to apply to the receiving [`TxGraph`](crate::tx_graph::TxGraph).
pub graph_update: crate::tx_graph::Update<A>,
/// The update to apply to the receiving [`LocalChain`](crate::local_chain::LocalChain).
pub chain_update: Option<CheckPoint>,
}
Expand Down Expand Up @@ -497,8 +497,8 @@ impl<K: Ord + Clone> FullScanRequest<K> {
#[derive(Debug)]
pub struct FullScanResult<K, A = ConfirmationBlockTime> {
/// The update to apply to the receiving [`LocalChain`](crate::local_chain::LocalChain).
pub graph_update: TxGraph<A>,
/// The update to apply to the receiving [`TxGraph`].
pub graph_update: crate::tx_graph::Update<A>,
/// The update to apply to the receiving [`TxGraph`](crate::tx_graph::TxGraph).
pub chain_update: Option<CheckPoint>,
/// Last active indices for the corresponding keychains (`K`).
pub last_active_indices: BTreeMap<K, u32>,
Expand Down
Loading
Loading