]> Untitled Git - bdk/commitdiff
chore(core)!: s/tx_graph::Update/TxUpdate/
authorLLFourn <lloyd.fourn@gmail.com>
Sun, 25 Aug 2024 05:35:18 +0000 (15:35 +1000)
committerLLFourn <lloyd.fourn@gmail.com>
Sun, 25 Aug 2024 05:42:45 +0000 (15:42 +1000)
We shouldn't refer to `tx_graph` in `bdk_core`. TxGraph happens to
consume `Update` but it doesn't conceptually own the definition of an
update to transactions.

I tried to also remove a lot of references to "graph" where they
shouldn't be. "graph" is a very general kind of data structure so we
should avoid referring to it where it's not relevant. `tx_update` is
much better than `graph_update`.

21 files changed:
crates/chain/src/indexed_tx_graph.rs
crates/chain/src/tx_graph.rs
crates/chain/tests/test_tx_graph.rs
crates/core/src/block_id.rs [new file with mode: 0644]
crates/core/src/chain_data.rs [deleted file]
crates/core/src/lib.rs
crates/core/src/spk_client.rs
crates/core/src/tx_update.rs [new file with mode: 0644]
crates/electrum/src/bdk_electrum_client.rs
crates/electrum/tests/test_electrum.rs
crates/esplora/src/async_ext.rs
crates/esplora/src/blocking_ext.rs
crates/esplora/src/lib.rs
crates/esplora/tests/async_ext.rs
crates/esplora/tests/blocking_ext.rs
crates/wallet/src/wallet/export.rs
crates/wallet/src/wallet/mod.rs
crates/wallet/tests/common.rs
crates/wallet/tests/wallet.rs
example-crates/example_electrum/src/main.rs
example-crates/example_esplora/src/main.rs

index 73ae458ffd500aff4379736308862c63069f8d80..ed2a1f0ce722b6744ff05f7af09fa5d5780677b2 100644 (file)
@@ -90,10 +90,10 @@ where
 
     /// Apply an `update` directly.
     ///
-    /// `update` is a [`tx_graph::Update<A>`] and the resultant changes is returned as [`ChangeSet`].
+    /// `update` is a [`tx_graph::TxUpdate<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> {
+    pub fn apply_update(&mut self, update: tx_graph::TxUpdate<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 }
@@ -114,7 +114,7 @@ where
     /// set to the current time.
     pub fn apply_update_at(
         &mut self,
-        update: tx_graph::Update<A>,
+        update: tx_graph::TxUpdate<A>,
         seen_at: Option<u64>,
     ) -> ChangeSet<A, I::ChangeSet> {
         let tx_graph = self.graph.apply_update_at(update, seen_at);
index 085418fc3ac97aaa35246de61bb492d4564989b5..127b47cf20e9c10cea3471fc014f9dcd5e933a55 100644 (file)
@@ -78,7 +78,7 @@
 //! # let tx_b = tx_from_hex(RAW_TX_2);
 //! let mut graph: TxGraph = TxGraph::default();
 //!
-//! let mut update = tx_graph::Update::default();
+//! let mut update = tx_graph::TxUpdate::default();
 //! update.txs.push(Arc::new(tx_a));
 //! update.txs.push(Arc::new(tx_b));
 //!
@@ -98,7 +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;
+pub use bdk_core::TxUpdate;
 use bitcoin::{Amount, OutPoint, ScriptBuf, SignedAmount, Transaction, TxOut, Txid};
 use core::fmt::{self, Formatter};
 use core::{
@@ -106,7 +106,7 @@ use core::{
     ops::{Deref, RangeInclusive},
 };
 
-impl<A> From<TxGraph<A>> for Update<A> {
+impl<A> From<TxGraph<A>> for TxUpdate<A> {
     fn from(graph: TxGraph<A>) -> Self {
         Self {
             txs: graph.full_txs().map(|tx_node| tx_node.tx).collect(),
@@ -120,8 +120,8 @@ impl<A> From<TxGraph<A>> for Update<A> {
     }
 }
 
-impl<A: Ord + Clone> From<Update<A>> for TxGraph<A> {
-    fn from(update: Update<A>) -> Self {
+impl<A: Ord + Clone> From<TxUpdate<A>> for TxGraph<A> {
+    fn from(update: TxUpdate<A>) -> Self {
         let mut graph = TxGraph::<A>::default();
         let _ = graph.apply_update_at(update, None);
         graph
@@ -655,7 +655,7 @@ impl<A: Clone + Ord> TxGraph<A> {
     /// exist in `update` but not in `self`).
     #[cfg(feature = "std")]
     #[cfg_attr(docsrs, doc(cfg(feature = "std")))]
-    pub fn apply_update(&mut self, update: Update<A>) -> ChangeSet<A> {
+    pub fn apply_update(&mut self, update: TxUpdate<A>) -> ChangeSet<A> {
         use std::time::*;
         let now = SystemTime::now()
             .duration_since(UNIX_EPOCH)
@@ -676,7 +676,7 @@ impl<A: Clone + Ord> TxGraph<A> {
     ///
     /// Use [`apply_update`](TxGraph::apply_update) to have the `seen_at` value automatically set
     /// to the current time.
-    pub fn apply_update_at(&mut self, update: Update<A>, seen_at: Option<u64>) -> ChangeSet<A> {
+    pub fn apply_update_at(&mut self, update: TxUpdate<A>, seen_at: Option<u64>) -> ChangeSet<A> {
         let mut changeset = ChangeSet::<A>::default();
         let mut unanchored_txs = HashSet::<Txid>::new();
         for tx in update.txs {
index 4ce6772bbd4098499e898bd4f1f8cb98e60fd5f3..a49c9e5f5d30c4cbd1bcd50259b3bf0fea09804c 100644 (file)
@@ -88,7 +88,7 @@ fn insert_txouts() {
 
     // Make the update graph
     let update = {
-        let mut update = tx_graph::Update::default();
+        let mut update = tx_graph::TxUpdate::default();
         for (outpoint, txout) in &update_ops {
             // Insert partials transactions.
             update.txouts.insert(*outpoint, txout.clone());
@@ -1137,12 +1137,12 @@ fn call_map_anchors_with_non_deterministic_anchor() {
     );
 }
 
-/// Tests `From` impls for conversion between [`TxGraph`] and [`tx_graph::Update`].
+/// Tests `From` impls for conversion between [`TxGraph`] and [`tx_graph::TxUpdate`].
 #[test]
 fn tx_graph_update_conversion() {
-    use tx_graph::Update;
+    use tx_graph::TxUpdate;
 
-    type TestCase = (&'static str, Update<ConfirmationBlockTime>);
+    type TestCase = (&'static str, TxUpdate<ConfirmationBlockTime>);
 
     fn make_tx(v: i32) -> Transaction {
         Transaction {
@@ -1161,24 +1161,24 @@ fn tx_graph_update_conversion() {
     }
 
     let test_cases: &[TestCase] = &[
-        ("empty_update", Update::default()),
+        ("empty_update", TxUpdate::default()),
         (
             "single_tx",
-            Update {
+            TxUpdate {
                 txs: vec![make_tx(0).into()],
                 ..Default::default()
             },
         ),
         (
             "two_txs",
-            Update {
+            TxUpdate {
                 txs: vec![make_tx(0).into(), make_tx(1).into()],
                 ..Default::default()
             },
         ),
         (
             "with_floating_txouts",
-            Update {
+            TxUpdate {
                 txs: vec![make_tx(0).into(), make_tx(1).into()],
                 txouts: [
                     (OutPoint::new(h!("a"), 0), make_txout(0)),
@@ -1191,7 +1191,7 @@ fn tx_graph_update_conversion() {
         ),
         (
             "with_anchors",
-            Update {
+            TxUpdate {
                 txs: vec![make_tx(0).into(), make_tx(1).into()],
                 txouts: [
                     (OutPoint::new(h!("a"), 0), make_txout(0)),
@@ -1209,7 +1209,7 @@ fn tx_graph_update_conversion() {
         ),
         (
             "with_seen_ats",
-            Update {
+            TxUpdate {
                 txs: vec![make_tx(0).into(), make_tx(1).into()],
                 txouts: [
                     (OutPoint::new(h!("a"), 0), make_txout(0)),
@@ -1230,7 +1230,7 @@ fn tx_graph_update_conversion() {
     for (test_name, update) in test_cases {
         let mut tx_graph = TxGraph::<ConfirmationBlockTime>::default();
         let _ = tx_graph.apply_update_at(update.clone(), None);
-        let update_from_tx_graph: Update<ConfirmationBlockTime> = tx_graph.into();
+        let update_from_tx_graph: TxUpdate<ConfirmationBlockTime> = tx_graph.into();
 
         assert_eq!(
             update
diff --git a/crates/core/src/block_id.rs b/crates/core/src/block_id.rs
new file mode 100644 (file)
index 0000000..2e64c9c
--- /dev/null
@@ -0,0 +1,51 @@
+use bitcoin::{hashes::Hash, BlockHash};
+
+/// A reference to a block in the canonical chain.
+#[derive(Debug, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
+pub struct BlockId {
+    /// The height of the block.
+    pub height: u32,
+    /// The hash of the block.
+    pub hash: BlockHash,
+}
+
+impl Default for BlockId {
+    fn default() -> Self {
+        Self {
+            height: Default::default(),
+            hash: BlockHash::all_zeros(),
+        }
+    }
+}
+
+impl From<(u32, BlockHash)> for BlockId {
+    fn from((height, hash): (u32, BlockHash)) -> Self {
+        Self { height, hash }
+    }
+}
+
+impl From<BlockId> for (u32, BlockHash) {
+    fn from(block_id: BlockId) -> Self {
+        (block_id.height, block_id.hash)
+    }
+}
+
+impl From<(&u32, &BlockHash)> for BlockId {
+    fn from((height, hash): (&u32, &BlockHash)) -> Self {
+        Self {
+            height: *height,
+            hash: *hash,
+        }
+    }
+}
+
+/// Represents the confirmation block and time of a transaction.
+#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
+pub struct ConfirmationBlockTime {
+    /// The anchor block.
+    pub block_id: BlockId,
+    /// The confirmation time of the transaction being anchored.
+    pub confirmation_time: u64,
+}
diff --git a/crates/core/src/chain_data.rs b/crates/core/src/chain_data.rs
deleted file mode 100644 (file)
index 2e64c9c..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-use bitcoin::{hashes::Hash, BlockHash};
-
-/// A reference to a block in the canonical chain.
-#[derive(Debug, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
-#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
-pub struct BlockId {
-    /// The height of the block.
-    pub height: u32,
-    /// The hash of the block.
-    pub hash: BlockHash,
-}
-
-impl Default for BlockId {
-    fn default() -> Self {
-        Self {
-            height: Default::default(),
-            hash: BlockHash::all_zeros(),
-        }
-    }
-}
-
-impl From<(u32, BlockHash)> for BlockId {
-    fn from((height, hash): (u32, BlockHash)) -> Self {
-        Self { height, hash }
-    }
-}
-
-impl From<BlockId> for (u32, BlockHash) {
-    fn from(block_id: BlockId) -> Self {
-        (block_id.height, block_id.hash)
-    }
-}
-
-impl From<(&u32, &BlockHash)> for BlockId {
-    fn from((height, hash): (&u32, &BlockHash)) -> Self {
-        Self {
-            height: *height,
-            hash: *hash,
-        }
-    }
-}
-
-/// Represents the confirmation block and time of a transaction.
-#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
-#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
-pub struct ConfirmationBlockTime {
-    /// The anchor block.
-    pub block_id: BlockId,
-    /// The confirmation time of the transaction being anchored.
-    pub confirmation_time: u64,
-}
index 038bee621639be3e2aad998cefae3a0dcb63ed07..aeb34dca342c654d097f9c5a245a104a0c5843f5 100644 (file)
@@ -59,55 +59,13 @@ pub type Indexed<T> = (u32, T);
 /// A tuple of keychain `K`, derivation index (`u32`) and a `T` associated with them.
 pub type KeychainIndexed<K, T> = ((K, u32), T);
 
-mod chain_data;
-pub use chain_data::*;
+mod block_id;
+pub use block_id::*;
 
 mod checkpoint;
 pub use checkpoint::*;
 
-pub mod spk_client;
-
-/// 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>,
-    }
+mod tx_update;
+pub use tx_update::*;
 
-    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);
-        }
-    }
-}
+pub mod spk_client;
index e54849fbbacb6ae200838b0823c3a3af37504300..1aceae5bbb4a38acd40e2d417f2e152c6331e39b 100644 (file)
@@ -323,18 +323,16 @@ impl<I> SyncRequest<I> {
 #[must_use]
 #[derive(Debug)]
 pub struct SyncResult<A = ConfirmationBlockTime> {
-    /// The update to apply to the receiving
-    /// [`TxGraph`](../../bdk_chain/tx_graph/struct.TxGraph.html).
-    pub graph_update: crate::tx_graph::Update<A>,
-    /// The update to apply to the receiving
-    /// [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
+    /// Relevant transaction data discovered during the scan.
+    pub tx_update: crate::TxUpdate<A>,
+    /// Changes to the chain discovered during the scan.
     pub chain_update: Option<CheckPoint>,
 }
 
 impl<A> Default for SyncResult<A> {
     fn default() -> Self {
         Self {
-            graph_update: Default::default(),
+            tx_update: Default::default(),
             chain_update: Default::default(),
         }
     }
@@ -462,19 +460,19 @@ impl<K: Ord + Clone> FullScanRequest<K> {
 #[must_use]
 #[derive(Debug)]
 pub struct FullScanResult<K, A = ConfirmationBlockTime> {
-    /// The update to apply to the receiving
-    /// [`LocalChain`](../../bdk_chain/local_chain/struct.LocalChain.html).
-    pub graph_update: crate::tx_graph::Update<A>,
-    /// The update to apply to the receiving [`TxGraph`](../../bdk_chain/tx_graph/struct.TxGraph.html).
-    pub chain_update: Option<CheckPoint>,
-    /// Last active indices for the corresponding keychains (`K`).
+    /// Relevant transaction data discovered during the scan.
+    pub tx_update: crate::TxUpdate<A>,
+    /// Last active indices for the corresponding keychains (`K`). An index is active if it had a
+    /// transaction associated with the script pubkey at that index.
     pub last_active_indices: BTreeMap<K, u32>,
+    /// Changes to the chain discovered during the scan.
+    pub chain_update: Option<CheckPoint>,
 }
 
 impl<K, A> Default for FullScanResult<K, A> {
     fn default() -> Self {
         Self {
-            graph_update: Default::default(),
+            tx_update: Default::default(),
             chain_update: Default::default(),
             last_active_indices: Default::default(),
         }
diff --git a/crates/core/src/tx_update.rs b/crates/core/src/tx_update.rs
new file mode 100644 (file)
index 0000000..a1ff75d
--- /dev/null
@@ -0,0 +1,43 @@
+use crate::collections::{BTreeMap, BTreeSet, HashMap};
+use alloc::{sync::Arc, vec::Vec};
+use bitcoin::{OutPoint, Transaction, TxOut, Txid};
+
+/// Data object used to communicate updates about relevant transactions from some chain data soruce
+/// to the core model (usually a `bdk_chain::TxGraph`).
+#[derive(Debug, Clone)]
+pub struct TxUpdate<A = ()> {
+    /// Full transactions. These are transactions that were determined to be relevant to the wallet
+    /// given the request.
+    pub txs: Vec<Arc<Transaction>>,
+    /// Floating txouts. These are `TxOut`s that exist but the whole transaction wasn't included in
+    /// `txs` since only knowing about the output is important. These are often used to help determine
+    /// the fee of a wallet transaction.
+    pub txouts: BTreeMap<OutPoint, TxOut>,
+    /// Transaction anchors. Anchors tells us a position in the chain where a transaction was
+    /// confirmed.
+    pub anchors: BTreeSet<(A, Txid)>,
+    /// Seen at times for transactions. This records when a transaction was most recently seen in
+    /// the user's mempool for the sake of tie-breaking other conflicting transactions.
+    pub seen_ats: HashMap<Txid, u64>,
+}
+
+impl<A> Default for TxUpdate<A> {
+    fn default() -> Self {
+        Self {
+            txs: Default::default(),
+            txouts: Default::default(),
+            anchors: Default::default(),
+            seen_ats: Default::default(),
+        }
+    }
+}
+
+impl<A: Ord> TxUpdate<A> {
+    /// Extend this update with `other`.
+    pub fn extend(&mut self, other: TxUpdate<A>) {
+        self.txs.extend(other.txs);
+        self.txouts.extend(other.txouts);
+        self.anchors.extend(other.anchors);
+        self.seen_ats.extend(other.seen_ats);
+    }
+}
index d78d7f64c3b28b3a16e372ceb6dcb1e12681df49..a98063336d880a645c5c970a2e555096b9a0ecae 100644 (file)
@@ -2,7 +2,7 @@ use bdk_core::{
     bitcoin::{block::Header, BlockHash, OutPoint, ScriptBuf, Transaction, Txid},
     collections::{BTreeMap, HashMap},
     spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
-    tx_graph, BlockId, CheckPoint, ConfirmationBlockTime,
+    BlockId, CheckPoint, ConfirmationBlockTime, TxUpdate,
 };
 use electrum_client::{ElectrumApi, Error, HeaderNotification};
 use std::{
@@ -134,12 +134,12 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             None => None,
         };
 
-        let mut graph_update = tx_graph::Update::<ConfirmationBlockTime>::default();
+        let mut tx_update = TxUpdate::<ConfirmationBlockTime>::default();
         let mut last_active_indices = BTreeMap::<K, u32>::default();
         for keychain in request.keychains() {
             let spks = request.iter_spks(keychain.clone());
             if let Some(last_active_index) =
-                self.populate_with_spks(&mut graph_update, spks, stop_gap, batch_size)?
+                self.populate_with_spks(&mut tx_update, spks, stop_gap, batch_size)?
             {
                 last_active_indices.insert(keychain, last_active_index);
             }
@@ -147,20 +147,20 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
 
         // Fetch previous `TxOut`s for fee calculation if flag is enabled.
         if fetch_prev_txouts {
-            self.fetch_prev_txout(&mut graph_update)?;
+            self.fetch_prev_txout(&mut tx_update)?;
         }
 
         let chain_update = match tip_and_latest_blocks {
             Some((chain_tip, latest_blocks)) => Some(chain_update(
                 chain_tip,
                 &latest_blocks,
-                graph_update.anchors.iter().cloned(),
+                tx_update.anchors.iter().cloned(),
             )?),
             _ => None,
         };
 
         Ok(FullScanResult {
-            graph_update,
+            tx_update,
             chain_update,
             last_active_indices,
         })
@@ -202,9 +202,9 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             None => None,
         };
 
-        let mut graph_update = tx_graph::Update::<ConfirmationBlockTime>::default();
+        let mut tx_update = TxUpdate::<ConfirmationBlockTime>::default();
         self.populate_with_spks(
-            &mut graph_update,
+            &mut tx_update,
             request
                 .iter_spks()
                 .enumerate()
@@ -212,37 +212,37 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             usize::MAX,
             batch_size,
         )?;
-        self.populate_with_txids(&mut graph_update, request.iter_txids())?;
-        self.populate_with_outpoints(&mut graph_update, request.iter_outpoints())?;
+        self.populate_with_txids(&mut tx_update, request.iter_txids())?;
+        self.populate_with_outpoints(&mut tx_update, request.iter_outpoints())?;
 
         // Fetch previous `TxOut`s for fee calculation if flag is enabled.
         if fetch_prev_txouts {
-            self.fetch_prev_txout(&mut graph_update)?;
+            self.fetch_prev_txout(&mut tx_update)?;
         }
 
         let chain_update = match tip_and_latest_blocks {
             Some((chain_tip, latest_blocks)) => Some(chain_update(
                 chain_tip,
                 &latest_blocks,
-                graph_update.anchors.iter().cloned(),
+                tx_update.anchors.iter().cloned(),
             )?),
             None => None,
         };
 
         Ok(SyncResult {
-            graph_update,
+            tx_update,
             chain_update,
         })
     }
 
-    /// Populate the `graph_update` with transactions/anchors associated with the given `spks`.
+    /// Populate the `tx_update` with transactions/anchors associated with the given `spks`.
     ///
     /// Transactions that contains an output with requested spk, or spends form an output with
-    /// requested spk will be added to `graph_update`. Anchors of the aforementioned transactions are
+    /// requested spk will be added to `tx_update`. Anchors of the aforementioned transactions are
     /// also included.
     fn populate_with_spks(
         &self,
-        graph_update: &mut tx_graph::Update<ConfirmationBlockTime>,
+        tx_update: &mut TxUpdate<ConfirmationBlockTime>,
         mut spks: impl Iterator<Item = (u32, ScriptBuf)>,
         stop_gap: usize,
         batch_size: usize,
@@ -275,20 +275,20 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
                 }
 
                 for tx_res in spk_history {
-                    graph_update.txs.push(self.fetch_tx(tx_res.tx_hash)?);
-                    self.validate_merkle_for_anchor(graph_update, tx_res.tx_hash, tx_res.height)?;
+                    tx_update.txs.push(self.fetch_tx(tx_res.tx_hash)?);
+                    self.validate_merkle_for_anchor(tx_update, tx_res.tx_hash, tx_res.height)?;
                 }
             }
         }
     }
 
-    /// Populate the `graph_update` with associated transactions/anchors of `outpoints`.
+    /// Populate the `tx_update` with associated transactions/anchors of `outpoints`.
     ///
     /// Transactions in which the outpoint resides, and transactions that spend from the outpoint are
     /// included. Anchors of the aforementioned transactions are included.
     fn populate_with_outpoints(
         &self,
-        graph_update: &mut tx_graph::Update<ConfirmationBlockTime>,
+        tx_update: &mut TxUpdate<ConfirmationBlockTime>,
         outpoints: impl IntoIterator<Item = OutPoint>,
     ) -> Result<(), Error> {
         for outpoint in outpoints {
@@ -311,8 +311,8 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
 
                 if !has_residing && res.tx_hash == op_txid {
                     has_residing = true;
-                    graph_update.txs.push(Arc::clone(&op_tx));
-                    self.validate_merkle_for_anchor(graph_update, res.tx_hash, res.height)?;
+                    tx_update.txs.push(Arc::clone(&op_tx));
+                    self.validate_merkle_for_anchor(tx_update, res.tx_hash, res.height)?;
                 }
 
                 if !has_spending && res.tx_hash != op_txid {
@@ -325,18 +325,18 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
                     if !has_spending {
                         continue;
                     }
-                    graph_update.txs.push(Arc::clone(&res_tx));
-                    self.validate_merkle_for_anchor(graph_update, res.tx_hash, res.height)?;
+                    tx_update.txs.push(Arc::clone(&res_tx));
+                    self.validate_merkle_for_anchor(tx_update, res.tx_hash, res.height)?;
                 }
             }
         }
         Ok(())
     }
 
-    /// Populate the `graph_update` with transactions/anchors of the provided `txids`.
+    /// Populate the `tx_update` with transactions/anchors of the provided `txids`.
     fn populate_with_txids(
         &self,
-        graph_update: &mut tx_graph::Update<ConfirmationBlockTime>,
+        tx_update: &mut TxUpdate<ConfirmationBlockTime>,
         txids: impl IntoIterator<Item = Txid>,
     ) -> Result<(), Error> {
         for txid in txids {
@@ -360,10 +360,10 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
                 .into_iter()
                 .find(|r| r.tx_hash == txid)
             {
-                self.validate_merkle_for_anchor(graph_update, txid, r.height)?;
+                self.validate_merkle_for_anchor(tx_update, txid, r.height)?;
             }
 
-            graph_update.txs.push(tx);
+            tx_update.txs.push(tx);
         }
         Ok(())
     }
@@ -372,7 +372,7 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
     // An anchor is inserted if the transaction is validated to be in a confirmed block.
     fn validate_merkle_for_anchor(
         &self,
-        graph_update: &mut tx_graph::Update<ConfirmationBlockTime>,
+        tx_update: &mut TxUpdate<ConfirmationBlockTime>,
         txid: Txid,
         confirmation_height: i32,
     ) -> Result<(), Error> {
@@ -399,7 +399,7 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             }
 
             if is_confirmed_tx {
-                graph_update.anchors.insert((
+                tx_update.anchors.insert((
                     ConfirmationBlockTime {
                         confirmation_time: header.time as u64,
                         block_id: BlockId {
@@ -418,17 +418,17 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
     // which we do not have by default. This data is needed to calculate the transaction fee.
     fn fetch_prev_txout(
         &self,
-        graph_update: &mut tx_graph::Update<ConfirmationBlockTime>,
+        tx_update: &mut TxUpdate<ConfirmationBlockTime>,
     ) -> Result<(), Error> {
         let mut no_dup = HashSet::<Txid>::new();
-        for tx in &graph_update.txs {
+        for tx in &tx_update.txs {
             if no_dup.insert(tx.compute_txid()) {
                 for vin in &tx.input {
                     let outpoint = vin.previous_output;
                     let vout = outpoint.vout;
                     let prev_tx = self.fetch_tx(outpoint.txid)?;
                     let txout = prev_tx.output[vout as usize].clone();
-                    let _ = graph_update.txouts.insert(outpoint, txout);
+                    let _ = tx_update.txouts.insert(outpoint, txout);
                 }
             }
         }
index d5e4a1596e748ac4f876b8877249b087f69750a6..5f032ba6cb58b43445530649ca67533130444adb 100644 (file)
@@ -49,7 +49,7 @@ where
             .apply_update(chain_update)
             .map_err(|err| anyhow::anyhow!("LocalChain update error: {:?}", err))?;
     }
-    let _ = graph.apply_update(update.graph_update.clone());
+    let _ = graph.apply_update(update.tx_update.clone());
 
     Ok(update)
 }
@@ -120,15 +120,15 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
         "update should not alter original checkpoint tip since we already started with all checkpoints",
     );
 
-    let graph_update = sync_update.graph_update;
+    let tx_update = sync_update.tx_update;
     let updated_graph = {
         let mut graph = TxGraph::<ConfirmationBlockTime>::default();
-        let _ = graph.apply_update(graph_update.clone());
+        let _ = graph.apply_update(tx_update.clone());
         graph
     };
     // Check to see if we have the floating txouts available from our two created transactions'
     // previous outputs in order to calculate transaction fees.
-    for tx in &graph_update.txs {
+    for tx in &tx_update.txs {
         // Retrieve the calculated fee from `TxGraph`, which will panic if we do not have the
         // floating txouts available from the transactions' previous outputs.
         let fee = updated_graph.calculate_fee(tx).expect("Fee must exist");
@@ -150,7 +150,7 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
     }
 
     assert_eq!(
-        graph_update
+        tx_update
             .txs
             .iter()
             .map(|tx| tx.compute_txid())
@@ -217,7 +217,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
             .spks_for_keychain(0, spks.clone());
         client.full_scan(request, 3, 1, false)?
     };
-    assert!(full_scan_update.graph_update.txs.is_empty());
+    assert!(full_scan_update.tx_update.txs.is_empty());
     assert!(full_scan_update.last_active_indices.is_empty());
     let full_scan_update = {
         let request = FullScanRequest::builder()
@@ -227,7 +227,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
     };
     assert_eq!(
         full_scan_update
-            .graph_update
+            .tx_update
             .txs
             .first()
             .unwrap()
@@ -259,7 +259,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 5, 1, false)?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
@@ -274,7 +274,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 6, 1, false)?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
@@ -478,7 +478,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
     )?;
 
     // Retain a snapshot of all anchors before reorg process.
-    let initial_anchors = update.graph_update.anchors.clone();
+    let initial_anchors = update.tx_update.anchors.clone();
     assert_eq!(initial_anchors.len(), REORG_COUNT);
     for i in 0..REORG_COUNT {
         let (anchor, txid) = initial_anchors.iter().nth(i).unwrap();
@@ -509,7 +509,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
         )?;
 
         // Check that no new anchors are added during current reorg.
-        assert!(initial_anchors.is_superset(&update.graph_update.anchors));
+        assert!(initial_anchors.is_superset(&update.tx_update.anchors));
 
         assert_eq!(
             get_balance(&recv_chain, &recv_graph)?,
index 041205c5e744a9586a97347d82bdfe8ca45808a3..04e07c7c4bad838509b8609e9ff285d47619126b 100644 (file)
@@ -3,7 +3,7 @@ use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
 use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
 use bdk_core::{
     bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
-    tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
+    BlockId, CheckPoint, ConfirmationBlockTime, Indexed, TxUpdate,
 };
 use futures::{stream::FuturesOrdered, TryStreamExt};
 
@@ -67,7 +67,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
             None
         };
 
-        let mut graph_update = tx_graph::Update::<ConfirmationBlockTime>::default();
+        let mut tx_update = TxUpdate::<ConfirmationBlockTime>::default();
         let mut inserted_txs = HashSet::<Txid>::new();
         let mut last_active_indices = BTreeMap::<K, u32>::new();
         for keychain in keychains {
@@ -80,7 +80,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
                 parallel_requests,
             )
             .await?;
-            graph_update.extend(update);
+            tx_update.extend(update);
             if let Some(last_active_index) = last_active_index {
                 last_active_indices.insert(keychain, last_active_index);
             }
@@ -88,14 +88,14 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
 
         let chain_update = match (chain_tip, latest_blocks) {
             (Some(chain_tip), Some(latest_blocks)) => {
-                Some(chain_update(self, &latest_blocks, &chain_tip, &graph_update.anchors).await?)
+                Some(chain_update(self, &latest_blocks, &chain_tip, &tx_update.anchors).await?)
             }
             _ => None,
         };
 
         Ok(FullScanResult {
             chain_update,
-            graph_update,
+            tx_update,
             last_active_indices,
         })
     }
@@ -114,9 +114,9 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
             None
         };
 
-        let mut graph_update = tx_graph::Update::<ConfirmationBlockTime>::default();
+        let mut tx_update = TxUpdate::<ConfirmationBlockTime>::default();
         let mut inserted_txs = HashSet::<Txid>::new();
-        graph_update.extend(
+        tx_update.extend(
             fetch_txs_with_spks(
                 self,
                 &mut inserted_txs,
@@ -125,7 +125,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
             )
             .await?,
         );
-        graph_update.extend(
+        tx_update.extend(
             fetch_txs_with_txids(
                 self,
                 &mut inserted_txs,
@@ -134,7 +134,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
             )
             .await?,
         );
-        graph_update.extend(
+        tx_update.extend(
             fetch_txs_with_outpoints(
                 self,
                 &mut inserted_txs,
@@ -146,14 +146,14 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
 
         let chain_update = match (chain_tip, latest_blocks) {
             (Some(chain_tip), Some(latest_blocks)) => {
-                Some(chain_update(self, &latest_blocks, &chain_tip, &graph_update.anchors).await?)
+                Some(chain_update(self, &latest_blocks, &chain_tip, &tx_update.anchors).await?)
             }
             _ => None,
         };
 
         Ok(SyncResult {
             chain_update,
-            graph_update,
+            tx_update,
         })
     }
 }
@@ -277,10 +277,10 @@ async fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>> + S
     mut keychain_spks: I,
     stop_gap: usize,
     parallel_requests: usize,
-) -> Result<(tx_graph::Update<ConfirmationBlockTime>, Option<u32>), Error> {
+) -> Result<(TxUpdate<ConfirmationBlockTime>, Option<u32>), Error> {
     type TxsOfSpkIndex = (u32, Vec<esplora_client::Tx>);
 
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
     let mut last_index = Option::<u32>::None;
     let mut last_active_index = Option::<u32>::None;
 
@@ -351,7 +351,7 @@ async fn fetch_txs_with_spks<I: IntoIterator<Item = ScriptBuf> + Send>(
     inserted_txs: &mut HashSet<Txid>,
     spks: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error>
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
 where
     I::IntoIter: Send,
 {
@@ -377,11 +377,11 @@ async fn fetch_txs_with_txids<I: IntoIterator<Item = Txid> + Send>(
     inserted_txs: &mut HashSet<Txid>,
     txids: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error>
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
 where
     I::IntoIter: Send,
 {
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
     // Only fetch for non-inserted txs.
     let mut txids = txids
         .into_iter()
@@ -426,12 +426,12 @@ async fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint> + Send>(
     inserted_txs: &mut HashSet<Txid>,
     outpoints: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error>
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error>
 where
     I::IntoIter: Send,
 {
     let outpoints = outpoints.into_iter().collect::<Vec<_>>();
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
 
     // make sure txs exists in graph and tx statuses are updated
     // TODO: We should maintain a tx cache (like we do with Electrum).
index d0744b4edd8c7cce8b2e00926d623b38c8feec9f..2552e6e8364889ea1a787934901ed282e40c1b56 100644 (file)
@@ -2,7 +2,7 @@ use bdk_core::collections::{BTreeMap, BTreeSet, HashSet};
 use bdk_core::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult};
 use bdk_core::{
     bitcoin::{BlockHash, OutPoint, ScriptBuf, Txid},
-    tx_graph, BlockId, CheckPoint, ConfirmationBlockTime, Indexed,
+    BlockId, CheckPoint, ConfirmationBlockTime, Indexed, TxUpdate,
 };
 use esplora_client::{OutputStatus, Tx};
 use std::thread::JoinHandle;
@@ -62,7 +62,7 @@ impl EsploraExt for esplora_client::BlockingClient {
             None
         };
 
-        let mut graph_update = tx_graph::Update::default();
+        let mut tx_update = TxUpdate::default();
         let mut inserted_txs = HashSet::<Txid>::new();
         let mut last_active_indices = BTreeMap::<K, u32>::new();
         for keychain in request.keychains() {
@@ -74,7 +74,7 @@ impl EsploraExt for esplora_client::BlockingClient {
                 stop_gap,
                 parallel_requests,
             )?;
-            graph_update.extend(update);
+            tx_update.extend(update);
             if let Some(last_active_index) = last_active_index {
                 last_active_indices.insert(keychain, last_active_index);
             }
@@ -85,14 +85,14 @@ impl EsploraExt for esplora_client::BlockingClient {
                 self,
                 &latest_blocks,
                 &chain_tip,
-                &graph_update.anchors,
+                &tx_update.anchors,
             )?),
             _ => None,
         };
 
         Ok(FullScanResult {
             chain_update,
-            graph_update,
+            tx_update,
             last_active_indices,
         })
     }
@@ -111,21 +111,21 @@ impl EsploraExt for esplora_client::BlockingClient {
             None
         };
 
-        let mut graph_update = tx_graph::Update::<ConfirmationBlockTime>::default();
+        let mut tx_update = TxUpdate::<ConfirmationBlockTime>::default();
         let mut inserted_txs = HashSet::<Txid>::new();
-        graph_update.extend(fetch_txs_with_spks(
+        tx_update.extend(fetch_txs_with_spks(
             self,
             &mut inserted_txs,
             request.iter_spks(),
             parallel_requests,
         )?);
-        graph_update.extend(fetch_txs_with_txids(
+        tx_update.extend(fetch_txs_with_txids(
             self,
             &mut inserted_txs,
             request.iter_txids(),
             parallel_requests,
         )?);
-        graph_update.extend(fetch_txs_with_outpoints(
+        tx_update.extend(fetch_txs_with_outpoints(
             self,
             &mut inserted_txs,
             request.iter_outpoints(),
@@ -137,14 +137,14 @@ impl EsploraExt for esplora_client::BlockingClient {
                 self,
                 &latest_blocks,
                 &chain_tip,
-                &graph_update.anchors,
+                &tx_update.anchors,
             )?),
             _ => None,
         };
 
         Ok(SyncResult {
             chain_update,
-            graph_update,
+            tx_update,
         })
     }
 }
@@ -254,10 +254,10 @@ fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<ScriptBuf>>>(
     mut keychain_spks: I,
     stop_gap: usize,
     parallel_requests: usize,
-) -> Result<(tx_graph::Update<ConfirmationBlockTime>, Option<u32>), Error> {
+) -> Result<(TxUpdate<ConfirmationBlockTime>, Option<u32>), Error> {
     type TxsOfSpkIndex = (u32, Vec<esplora_client::Tx>);
 
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
     let mut last_index = Option::<u32>::None;
     let mut last_active_index = Option::<u32>::None;
 
@@ -331,7 +331,7 @@ fn fetch_txs_with_spks<I: IntoIterator<Item = ScriptBuf>>(
     inserted_txs: &mut HashSet<Txid>,
     spks: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error> {
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error> {
     fetch_txs_with_keychain_spks(
         client,
         inserted_txs,
@@ -353,8 +353,8 @@ fn fetch_txs_with_txids<I: IntoIterator<Item = Txid>>(
     inserted_txs: &mut HashSet<Txid>,
     txids: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error> {
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error> {
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
     // Only fetch for non-inserted txs.
     let mut txids = txids
         .into_iter()
@@ -405,9 +405,9 @@ fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint>>(
     inserted_txs: &mut HashSet<Txid>,
     outpoints: I,
     parallel_requests: usize,
-) -> Result<tx_graph::Update<ConfirmationBlockTime>, Error> {
+) -> Result<TxUpdate<ConfirmationBlockTime>, Error> {
     let outpoints = outpoints.into_iter().collect::<Vec<_>>();
-    let mut update = tx_graph::Update::<ConfirmationBlockTime>::default();
+    let mut update = TxUpdate::<ConfirmationBlockTime>::default();
 
     // make sure txs exists in graph and tx statuses are updated
     // TODO: We should maintain a tx cache (like we do with Electrum).
index 7aad133b4497f30771fc6efe7841a6d77c3d3f52..a166b6f9fb9c7eb8f1f1b094fbd411b080d9981d 100644 (file)
@@ -21,7 +21,7 @@
 //! [`esplora_client::AsyncClient`].
 
 use bdk_core::bitcoin::{Amount, OutPoint, TxOut, Txid};
-use bdk_core::{tx_graph, BlockId, ConfirmationBlockTime};
+use bdk_core::{BlockId, ConfirmationBlockTime, TxUpdate};
 use esplora_client::TxStatus;
 
 pub use esplora_client;
@@ -37,7 +37,7 @@ mod async_ext;
 pub use async_ext::*;
 
 fn insert_anchor_from_status(
-    update: &mut tx_graph::Update<ConfirmationBlockTime>,
+    update: &mut TxUpdate<ConfirmationBlockTime>,
     txid: Txid,
     status: TxStatus,
 ) {
@@ -59,7 +59,7 @@ fn insert_anchor_from_status(
 /// Inserts floating txouts into `tx_graph` using [`Vin`](esplora_client::api::Vin)s returned by
 /// Esplora.
 fn insert_prevouts(
-    update: &mut tx_graph::Update<ConfirmationBlockTime>,
+    update: &mut TxUpdate<ConfirmationBlockTime>,
     esplora_inputs: impl IntoIterator<Item = esplora_client::api::Vin>,
 ) {
     let prevouts = esplora_inputs
index 7b0ef7fa646790a610b2ac4cd0039c689c1e4895..b535d2bfa0ef791287e716c775112fd29bd08307 100644 (file)
@@ -78,15 +78,15 @@ pub async fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
         "update should not alter original checkpoint tip since we already started with all checkpoints",
     );
 
-    let graph_update = sync_update.graph_update;
+    let tx_update = sync_update.tx_update;
     let updated_graph = {
         let mut graph = TxGraph::<ConfirmationBlockTime>::default();
-        let _ = graph.apply_update(graph_update.clone());
+        let _ = graph.apply_update(tx_update.clone());
         graph
     };
     // Check to see if we have the floating txouts available from our two created transactions'
     // previous outputs in order to calculate transaction fees.
-    for tx in &graph_update.txs {
+    for tx in &tx_update.txs {
         // Retrieve the calculated fee from `TxGraph`, which will panic if we do not have the
         // floating txouts available from the transactions' previous outputs.
         let fee = updated_graph.calculate_fee(tx).expect("Fee must exist");
@@ -108,7 +108,7 @@ pub async fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
     }
 
     assert_eq!(
-        graph_update
+        tx_update
             .txs
             .iter()
             .map(|tx| tx.compute_txid())
@@ -177,7 +177,7 @@ pub async fn test_async_update_tx_graph_stop_gap() -> anyhow::Result<()> {
             .spks_for_keychain(0, spks.clone());
         client.full_scan(request, 3, 1).await?
     };
-    assert!(full_scan_update.graph_update.txs.is_empty());
+    assert!(full_scan_update.tx_update.txs.is_empty());
     assert!(full_scan_update.last_active_indices.is_empty());
     let full_scan_update = {
         let request = FullScanRequest::builder()
@@ -187,7 +187,7 @@ pub async fn test_async_update_tx_graph_stop_gap() -> anyhow::Result<()> {
     };
     assert_eq!(
         full_scan_update
-            .graph_update
+            .tx_update
             .txs
             .first()
             .unwrap()
@@ -221,7 +221,7 @@ pub async fn test_async_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 5, 1).await?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
@@ -236,7 +236,7 @@ pub async fn test_async_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 6, 1).await?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
index b3833b89957199bb8fa86c0d74de7954c25222f3..d4191ceb0d7ec50e88559f93acf212d680755151 100644 (file)
@@ -78,15 +78,15 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
         "update should not alter original checkpoint tip since we already started with all checkpoints",
     );
 
-    let graph_update = sync_update.graph_update;
+    let tx_update = sync_update.tx_update;
     let updated_graph = {
         let mut graph = TxGraph::<ConfirmationBlockTime>::default();
-        let _ = graph.apply_update(graph_update.clone());
+        let _ = graph.apply_update(tx_update.clone());
         graph
     };
     // Check to see if we have the floating txouts available from our two created transactions'
     // previous outputs in order to calculate transaction fees.
-    for tx in &graph_update.txs {
+    for tx in &tx_update.txs {
         // Retrieve the calculated fee from `TxGraph`, which will panic if we do not have the
         // floating txouts available from the transactions' previous outputs.
         let fee = updated_graph.calculate_fee(tx).expect("Fee must exist");
@@ -108,7 +108,7 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
     }
 
     assert_eq!(
-        graph_update
+        tx_update
             .txs
             .iter()
             .map(|tx| tx.compute_txid())
@@ -177,7 +177,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
             .spks_for_keychain(0, spks.clone());
         client.full_scan(request, 3, 1)?
     };
-    assert!(full_scan_update.graph_update.txs.is_empty());
+    assert!(full_scan_update.tx_update.txs.is_empty());
     assert!(full_scan_update.last_active_indices.is_empty());
     let full_scan_update = {
         let request = FullScanRequest::builder()
@@ -187,7 +187,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
     };
     assert_eq!(
         full_scan_update
-            .graph_update
+            .tx_update
             .txs
             .first()
             .unwrap()
@@ -221,7 +221,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 5, 1)?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
@@ -236,7 +236,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
         client.full_scan(request, 6, 1)?
     };
     let txs: HashSet<_> = full_scan_update
-        .graph_update
+        .tx_update
         .txs
         .iter()
         .map(|tx| tx.compute_txid())
index 386d9d4e35314a4ab338965421a33e424f619b09..ad5a6b2a8aa97bac6095dc829a79ca5a4f93c7d5 100644 (file)
@@ -255,7 +255,7 @@ mod test {
         };
         wallet
             .apply_update(Update {
-                graph: tx_graph::Update {
+                tx_update: tx_graph::TxUpdate {
                     anchors: [(anchor, txid)].into_iter().collect(),
                     ..Default::default()
                 },
index 72c42ddfed4e4f08cd4bb669b3e350558e21291e..5cad6bb867998c67199b019a17d656307b894773 100644 (file)
@@ -33,7 +33,7 @@ use bdk_chain::{
         FullScanRequest, FullScanRequestBuilder, FullScanResult, SyncRequest, SyncRequestBuilder,
         SyncResult,
     },
-    tx_graph::{CanonicalTx, TxGraph, TxNode},
+    tx_graph::{CanonicalTx, TxGraph, TxNode, TxUpdate},
     BlockId, ChainPosition, ConfirmationBlockTime, ConfirmationTime, DescriptorExt, FullTxOut,
     Indexed, IndexedTxGraph, Merge,
 };
@@ -132,7 +132,7 @@ pub struct Update {
     pub last_active_indices: BTreeMap<KeychainKind, u32>,
 
     /// Update for the wallet's internal [`TxGraph`].
-    pub graph: chain::tx_graph::Update<ConfirmationBlockTime>,
+    pub tx_update: TxUpdate<ConfirmationBlockTime>,
 
     /// Update for the wallet's internal [`LocalChain`].
     ///
@@ -144,7 +144,7 @@ impl From<FullScanResult<KeychainKind>> for Update {
     fn from(value: FullScanResult<KeychainKind>) -> Self {
         Self {
             last_active_indices: value.last_active_indices,
-            graph: value.graph_update,
+            tx_update: value.tx_update,
             chain: value.chain_update,
         }
     }
@@ -154,7 +154,7 @@ impl From<SyncResult> for Update {
     fn from(value: SyncResult) -> Self {
         Self {
             last_active_indices: BTreeMap::new(),
-            graph: value.graph_update,
+            tx_update: value.tx_update,
             chain: value.chain_update,
         }
     }
@@ -2318,7 +2318,7 @@ impl Wallet {
         changeset.merge(index_changeset.into());
         changeset.merge(
             self.indexed_graph
-                .apply_update_at(update.graph, seen_at)
+                .apply_update_at(update.tx_update, seen_at)
                 .into(),
         );
         self.stage.merge(changeset);
@@ -2624,7 +2624,7 @@ macro_rules! doctest_wallet {
             block_id,
         };
         let update = Update {
-            graph: tx_graph::Update {
+            tx_update: tx_graph::TxUpdate {
                 anchors: [(anchor, txid)].into_iter().collect(),
                 ..Default::default()
             },
index 561a9a5fb6b758e5cd4c913f656c6cbfeb46b6ef..375d680d17620b844b6747a67e80276ae0c53760 100644 (file)
@@ -220,7 +220,7 @@ pub fn insert_anchor_from_conf(wallet: &mut Wallet, txid: Txid, position: Confir
 
         wallet
             .apply_update(Update {
-                graph: tx_graph::Update {
+                tx_update: tx_graph::TxUpdate {
                     anchors: [(anchor, txid)].into(),
                     ..Default::default()
                 },
index 2431616584e336d16f7ad9a1c7e754ebfe15f432..2da25cd28e019ce191a7db6f6597c260d9c8a684 100644 (file)
@@ -83,7 +83,7 @@ fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
     use bdk_wallet::Update;
     wallet
         .apply_update(Update {
-            graph: tx_graph::Update {
+            tx_update: tx_graph::TxUpdate {
                 seen_ats: [(txid, seen_at)].into_iter().collect(),
                 ..Default::default()
             },
index 21910cf6604576b4911e195473d120236c7c4971..9c705a3df65a1834f1256937ba31e5a9c48a0a82 100644 (file)
@@ -136,7 +136,7 @@ fn main() -> anyhow::Result<()> {
             .map(|tx_node| tx_node.tx),
     );
 
-    let (chain_update, graph_update, keychain_update) = match electrum_cmd.clone() {
+    let (chain_update, tx_update, keychain_update) = match electrum_cmd.clone() {
         ElectrumCommands::Scan {
             stop_gap,
             scan_options,
@@ -182,7 +182,7 @@ fn main() -> anyhow::Result<()> {
                 .context("scanning the blockchain")?;
             (
                 res.chain_update,
-                res.graph_update,
+                res.tx_update,
                 Some(res.last_active_indices),
             )
         }
@@ -251,7 +251,7 @@ fn main() -> anyhow::Result<()> {
             // drop lock on graph and chain
             drop((graph, chain));
 
-            (res.chain_update, res.graph_update, None)
+            (res.chain_update, res.tx_update, None)
         }
     };
 
@@ -267,7 +267,7 @@ fn main() -> anyhow::Result<()> {
             let keychain_changeset = graph.index.reveal_to_target_multi(&keychain_update);
             indexed_tx_graph_changeset.merge(keychain_changeset.into());
         }
-        indexed_tx_graph_changeset.merge(graph.apply_update(graph_update));
+        indexed_tx_graph_changeset.merge(graph.apply_update(tx_update));
 
         ChangeSet {
             local_chain: chain_changeset,
index 7a40058787631884c3f9688bc931d526ddd2da4a..cba86b86200cab99e1b870c0ce163ac231b96970 100644 (file)
@@ -164,7 +164,7 @@ fn main() -> anyhow::Result<()> {
             };
 
             // The client scans keychain spks for transaction histories, stopping after `stop_gap`
-            // is reached. It returns a `TxGraph` update (`graph_update`) and a structure that
+            // is reached. It returns a `TxGraph` update (`tx_update`) and a structure that
             // represents the last active spk derivation indices of keychains
             // (`keychain_indices_update`).
             let update = client
@@ -183,7 +183,7 @@ fn main() -> anyhow::Result<()> {
                     let index_changeset = graph
                         .index
                         .reveal_to_target_multi(&update.last_active_indices);
-                    let mut indexed_tx_graph_changeset = graph.apply_update(update.graph_update);
+                    let mut indexed_tx_graph_changeset = graph.apply_update(update.tx_update);
                     indexed_tx_graph_changeset.merge(index_changeset.into());
                     indexed_tx_graph_changeset
                 },
@@ -269,7 +269,7 @@ fn main() -> anyhow::Result<()> {
                     .lock()
                     .unwrap()
                     .apply_update(update.chain_update.expect("request has chain tip"))?,
-                graph.lock().unwrap().apply_update(update.graph_update),
+                graph.lock().unwrap().apply_update(update.tx_update),
             )
         }
     };