Skip to content

Commit bdea871

Browse files
committed
feat!: move tx_graph::Update to bdk_core
1 parent 77e31c7 commit bdea871

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,14 @@ use crate::{Anchor, Balance, ChainOracle, ChainPosition, FullTxOut, Merge};
9898
use alloc::collections::vec_deque::VecDeque;
9999
use alloc::sync::Arc;
100100
use alloc::vec::Vec;
101+
pub use bdk_core::tx_graph::Update;
101102
use bitcoin::{Amount, OutPoint, ScriptBuf, SignedAmount, Transaction, TxOut, Txid};
102103
use core::fmt::{self, Formatter};
103104
use core::{
104105
convert::Infallible,
105106
ops::{Deref, RangeInclusive},
106107
};
107108

108-
/// Data object used to update the [`TxGraph`] with.
109-
#[derive(Debug, Clone)]
110-
pub struct Update<A = ()> {
111-
/// Full transactions.
112-
pub txs: Vec<Arc<Transaction>>,
113-
/// Floating txouts.
114-
pub txouts: BTreeMap<OutPoint, TxOut>,
115-
/// Transaction anchors.
116-
pub anchors: BTreeSet<(A, Txid)>,
117-
/// Seen at times for transactions.
118-
pub seen_ats: HashMap<Txid, u64>,
119-
}
120-
121-
impl<A> Default for Update<A> {
122-
fn default() -> Self {
123-
Self {
124-
txs: Default::default(),
125-
txouts: Default::default(),
126-
anchors: Default::default(),
127-
seen_ats: Default::default(),
128-
}
129-
}
130-
}
131-
132109
impl<A> From<TxGraph<A>> for Update<A> {
133110
fn from(graph: TxGraph<A>) -> Self {
134111
Self {
@@ -151,16 +128,6 @@ impl<A: Ord + Clone> From<Update<A>> for TxGraph<A> {
151128
}
152129
}
153130

154-
impl<A: Ord> Update<A> {
155-
/// Extend this update with `other`.
156-
pub fn extend(&mut self, other: Update<A>) {
157-
self.txs.extend(other.txs);
158-
self.txouts.extend(other.txouts);
159-
self.anchors.extend(other.anchors);
160-
self.seen_ats.extend(other.seen_ats);
161-
}
162-
}
163-
164131
/// A graph of transactions and spends.
165132
///
166133
/// See the [module-level documentation] for more.

crates/core/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,48 @@ pub use chain_data::*;
5959

6060
mod checkpoint;
6161
pub use checkpoint::*;
62+
63+
/// Core structures for [`TxGraph`].
64+
///
65+
/// [`TxGraph`]: https://docs.rs/bdk_chain/latest/bdk_chain/tx_graph/struct.TxGraph.html
66+
pub mod tx_graph {
67+
use crate::collections::{BTreeMap, BTreeSet, HashMap};
68+
use alloc::{sync::Arc, vec::Vec};
69+
use bitcoin::{OutPoint, Transaction, TxOut, Txid};
70+
71+
/// Data object used to update a [`TxGraph`].
72+
///
73+
/// [`TxGraph`]: https://docs.rs/bdk_chain/latest/bdk_chain/tx_graph/struct.TxGraph.html
74+
#[derive(Debug, Clone)]
75+
pub struct Update<A = ()> {
76+
/// Full transactions.
77+
pub txs: Vec<Arc<Transaction>>,
78+
/// Floating txouts.
79+
pub txouts: BTreeMap<OutPoint, TxOut>,
80+
/// Transaction anchors.
81+
pub anchors: BTreeSet<(A, Txid)>,
82+
/// Seen at times for transactions.
83+
pub seen_ats: HashMap<Txid, u64>,
84+
}
85+
86+
impl<A> Default for Update<A> {
87+
fn default() -> Self {
88+
Self {
89+
txs: Default::default(),
90+
txouts: Default::default(),
91+
anchors: Default::default(),
92+
seen_ats: Default::default(),
93+
}
94+
}
95+
}
96+
97+
impl<A: Ord> Update<A> {
98+
/// Extend this update with `other`.
99+
pub fn extend(&mut self, other: Update<A>) {
100+
self.txs.extend(other.txs);
101+
self.txouts.extend(other.txouts);
102+
self.anchors.extend(other.anchors);
103+
self.seen_ats.extend(other.seen_ats);
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)