Skip to content

Commit dad9545

Browse files
authored
Merge pull request #1568 from evanlinjin/tx_graph_update
Introduce `tx_graph::Update` and simplify `TxGraph` update logic
2 parents 9e6ac72 + ccb8c79 commit dad9545

File tree

21 files changed

+749
-631
lines changed

21 files changed

+749
-631
lines changed

crates/chain/src/indexed_tx_graph.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,36 @@ where
9090

9191
/// Apply an `update` directly.
9292
///
93-
/// `update` is a [`TxGraph<A>`] and the resultant changes is returned as [`ChangeSet`].
94-
pub fn apply_update(&mut self, update: TxGraph<A>) -> ChangeSet<A, I::ChangeSet> {
95-
let graph = self.graph.apply_update(update);
96-
let indexer = self.index_tx_graph_changeset(&graph);
97-
ChangeSet {
98-
tx_graph: graph,
99-
indexer,
100-
}
93+
/// `update` is a [`tx_graph::Update<A>`] and the resultant changes is returned as [`ChangeSet`].
94+
#[cfg(feature = "std")]
95+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
96+
pub fn apply_update(&mut self, update: tx_graph::Update<A>) -> ChangeSet<A, I::ChangeSet> {
97+
let tx_graph = self.graph.apply_update(update);
98+
let indexer = self.index_tx_graph_changeset(&tx_graph);
99+
ChangeSet { tx_graph, indexer }
100+
}
101+
102+
/// Apply the given `update` with an optional `seen_at` timestamp.
103+
///
104+
/// `seen_at` represents when the update is seen (in unix seconds). It is used to determine the
105+
/// `last_seen`s for all transactions in the update which have no corresponding anchor(s). The
106+
/// `last_seen` value is used internally to determine precedence of conflicting unconfirmed
107+
/// transactions (where the transaction with the lower `last_seen` value is omitted from the
108+
/// canonical history).
109+
///
110+
/// Not setting a `seen_at` value means unconfirmed transactions introduced by this update will
111+
/// not be part of the canonical history of transactions.
112+
///
113+
/// Use [`apply_update`](IndexedTxGraph::apply_update) to have the `seen_at` value automatically
114+
/// set to the current time.
115+
pub fn apply_update_at(
116+
&mut self,
117+
update: tx_graph::Update<A>,
118+
seen_at: Option<u64>,
119+
) -> ChangeSet<A, I::ChangeSet> {
120+
let tx_graph = self.graph.apply_update_at(update, seen_at);
121+
let indexer = self.index_tx_graph_changeset(&tx_graph);
122+
ChangeSet { tx_graph, indexer }
101123
}
102124

103125
/// Insert a floating `txout` of given `outpoint`.

crates/chain/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
//!
1818
//! [Bitcoin Dev Kit]: https://bitcoindevkit.org/
1919
20+
// only enables the `doc_cfg` feature when the `docsrs` configuration attribute is defined
21+
#![cfg_attr(docsrs, feature(doc_cfg))]
22+
#![cfg_attr(
23+
docsrs,
24+
doc(html_logo_url = "https://github.com/bitcoindevkit/bdk/raw/master/static/bdk.png")
25+
)]
2026
#![no_std]
2127
#![warn(missing_docs)]
2228

crates/chain/src/spk_client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
alloc::{boxed::Box, collections::VecDeque, vec::Vec},
44
collections::BTreeMap,
55
local_chain::CheckPoint,
6-
ConfirmationBlockTime, Indexed, TxGraph,
6+
ConfirmationBlockTime, Indexed,
77
};
88
use bitcoin::{OutPoint, Script, ScriptBuf, Txid};
99

@@ -345,8 +345,8 @@ impl<I> SyncRequest<I> {
345345
#[must_use]
346346
#[derive(Debug)]
347347
pub struct SyncResult<A = ConfirmationBlockTime> {
348-
/// The update to apply to the receiving [`TxGraph`].
349-
pub graph_update: TxGraph<A>,
348+
/// The update to apply to the receiving [`TxGraph`](crate::tx_graph::TxGraph).
349+
pub graph_update: crate::tx_graph::Update<A>,
350350
/// The update to apply to the receiving [`LocalChain`](crate::local_chain::LocalChain).
351351
pub chain_update: Option<CheckPoint>,
352352
}
@@ -497,8 +497,8 @@ impl<K: Ord + Clone> FullScanRequest<K> {
497497
#[derive(Debug)]
498498
pub struct FullScanResult<K, A = ConfirmationBlockTime> {
499499
/// The update to apply to the receiving [`LocalChain`](crate::local_chain::LocalChain).
500-
pub graph_update: TxGraph<A>,
501-
/// The update to apply to the receiving [`TxGraph`].
500+
pub graph_update: crate::tx_graph::Update<A>,
501+
/// The update to apply to the receiving [`TxGraph`](crate::tx_graph::TxGraph).
502502
pub chain_update: Option<CheckPoint>,
503503
/// Last active indices for the corresponding keychains (`K`).
504504
pub last_active_indices: BTreeMap<K, u32>,

0 commit comments

Comments
 (0)