From: 志宇 Date: Fri, 23 Aug 2024 16:57:59 +0000 (+0000) Subject: feat!: move `tx_graph::Update` to `bdk_core` X-Git-Tag: v1.0.0-beta.2~2^2~5 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.EncoderStringWriter.html?a=commitdiff_plain;h=bdea871a0d0d337772f226fdcf5cd734f3d857ba;p=bdk feat!: move `tx_graph::Update` to `bdk_core` --- diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 206aaf11..085418fc 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -98,6 +98,7 @@ use crate::{Anchor, Balance, ChainOracle, ChainPosition, FullTxOut, Merge}; use alloc::collections::vec_deque::VecDeque; use alloc::sync::Arc; use alloc::vec::Vec; +pub use bdk_core::tx_graph::Update; use bitcoin::{Amount, OutPoint, ScriptBuf, SignedAmount, Transaction, TxOut, Txid}; use core::fmt::{self, Formatter}; use core::{ @@ -105,30 +106,6 @@ use core::{ ops::{Deref, RangeInclusive}, }; -/// Data object used to update the [`TxGraph`] with. -#[derive(Debug, Clone)] -pub struct Update { - /// Full transactions. - pub txs: Vec>, - /// Floating txouts. - pub txouts: BTreeMap, - /// Transaction anchors. - pub anchors: BTreeSet<(A, Txid)>, - /// Seen at times for transactions. - pub seen_ats: HashMap, -} - -impl Default for Update { - fn default() -> Self { - Self { - txs: Default::default(), - txouts: Default::default(), - anchors: Default::default(), - seen_ats: Default::default(), - } - } -} - impl From> for Update { fn from(graph: TxGraph) -> Self { Self { @@ -151,16 +128,6 @@ impl From> for TxGraph { } } -impl Update { - /// Extend this update with `other`. - pub fn extend(&mut self, other: Update) { - self.txs.extend(other.txs); - self.txouts.extend(other.txouts); - self.anchors.extend(other.anchors); - self.seen_ats.extend(other.seen_ats); - } -} - /// A graph of transactions and spends. /// /// See the [module-level documentation] for more. diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index f8ac5e32..bed9da4a 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -59,3 +59,48 @@ pub use chain_data::*; mod checkpoint; pub use checkpoint::*; + +/// Core structures for [`TxGraph`]. +/// +/// [`TxGraph`]: https://docs.rs/bdk_chain/latest/bdk_chain/tx_graph/struct.TxGraph.html +pub mod tx_graph { + use crate::collections::{BTreeMap, BTreeSet, HashMap}; + use alloc::{sync::Arc, vec::Vec}; + use bitcoin::{OutPoint, Transaction, TxOut, Txid}; + + /// Data object used to update a [`TxGraph`]. + /// + /// [`TxGraph`]: https://docs.rs/bdk_chain/latest/bdk_chain/tx_graph/struct.TxGraph.html + #[derive(Debug, Clone)] + pub struct Update { + /// Full transactions. + pub txs: Vec>, + /// Floating txouts. + pub txouts: BTreeMap, + /// Transaction anchors. + pub anchors: BTreeSet<(A, Txid)>, + /// Seen at times for transactions. + pub seen_ats: HashMap, + } + + impl Default for Update { + fn default() -> Self { + Self { + txs: Default::default(), + txouts: Default::default(), + anchors: Default::default(), + seen_ats: Default::default(), + } + } + } + + impl Update { + /// Extend this update with `other`. + pub fn extend(&mut self, other: Update) { + self.txs.extend(other.txs); + self.txouts.extend(other.txouts); + self.anchors.extend(other.anchors); + self.seen_ats.extend(other.seen_ats); + } + } +}