]> Untitled Git - bdk/commitdiff
feat!: move `tx_graph::Update` to `bdk_core`
author志宇 <hello@evanlinjin.me>
Fri, 23 Aug 2024 16:57:59 +0000 (16:57 +0000)
committer志宇 <hello@evanlinjin.me>
Sat, 24 Aug 2024 16:17:06 +0000 (16:17 +0000)
crates/chain/src/tx_graph.rs
crates/core/src/lib.rs

index 206aaf11e9afafc18ea9110b543d15def0077c45..085418fc3ac97aaa35246de61bb492d4564989b5 100644 (file)
@@ -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<A = ()> {
-    /// Full transactions.
-    pub txs: Vec<Arc<Transaction>>,
-    /// Floating txouts.
-    pub txouts: BTreeMap<OutPoint, TxOut>,
-    /// Transaction anchors.
-    pub anchors: BTreeSet<(A, Txid)>,
-    /// Seen at times for transactions.
-    pub seen_ats: HashMap<Txid, u64>,
-}
-
-impl<A> Default for Update<A> {
-    fn default() -> Self {
-        Self {
-            txs: Default::default(),
-            txouts: Default::default(),
-            anchors: Default::default(),
-            seen_ats: Default::default(),
-        }
-    }
-}
-
 impl<A> From<TxGraph<A>> for Update<A> {
     fn from(graph: TxGraph<A>) -> Self {
         Self {
@@ -151,16 +128,6 @@ impl<A: Ord + Clone> From<Update<A>> for TxGraph<A> {
     }
 }
 
-impl<A: Ord> Update<A> {
-    /// Extend this update with `other`.
-    pub fn extend(&mut self, other: Update<A>) {
-        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.
index f8ac5e328bc71dee7200a7b3c8816cef66731cc0..bed9da4a116fc9532187eb65db508c636fd713e7 100644 (file)
@@ -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<A = ()> {
+        /// Full transactions.
+        pub txs: Vec<Arc<Transaction>>,
+        /// Floating txouts.
+        pub txouts: BTreeMap<OutPoint, TxOut>,
+        /// Transaction anchors.
+        pub anchors: BTreeSet<(A, Txid)>,
+        /// Seen at times for transactions.
+        pub seen_ats: HashMap<Txid, u64>,
+    }
+
+    impl<A> Default for Update<A> {
+        fn default() -> Self {
+            Self {
+                txs: Default::default(),
+                txouts: Default::default(),
+                anchors: Default::default(),
+                seen_ats: Default::default(),
+            }
+        }
+    }
+
+    impl<A: Ord> Update<A> {
+        /// Extend this update with `other`.
+        pub fn extend(&mut self, other: Update<A>) {
+            self.txs.extend(other.txs);
+            self.txouts.extend(other.txouts);
+            self.anchors.extend(other.anchors);
+            self.seen_ats.extend(other.seen_ats);
+        }
+    }
+}