|
3 | 3 | //! This is essentially a [`TxGraph`] combined with an indexer. |
4 | 4 |
|
5 | 5 | use alloc::vec::Vec; |
6 | | -use bitcoin::{Block, OutPoint, Transaction, TxOut}; |
| 6 | +use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid}; |
7 | 7 |
|
8 | 8 | use crate::{ |
9 | 9 | keychain, |
@@ -103,32 +103,25 @@ where |
103 | 103 | } |
104 | 104 |
|
105 | 105 | /// Insert and index a transaction into the graph. |
106 | | - /// |
107 | | - /// `anchors` can be provided to anchor the transaction to various blocks. `seen_at` is a |
108 | | - /// unix timestamp of when the transaction is last seen. |
109 | | - pub fn insert_tx( |
110 | | - &mut self, |
111 | | - tx: &Transaction, |
112 | | - anchors: impl IntoIterator<Item = A>, |
113 | | - seen_at: Option<u64>, |
114 | | - ) -> ChangeSet<A, I::ChangeSet> { |
115 | | - let txid = tx.txid(); |
116 | | - |
117 | | - let mut graph = tx_graph::ChangeSet::default(); |
118 | | - if self.graph.get_tx(txid).is_none() { |
119 | | - graph.append(self.graph.insert_tx(tx.clone())); |
120 | | - } |
121 | | - for anchor in anchors.into_iter() { |
122 | | - graph.append(self.graph.insert_anchor(txid, anchor)); |
123 | | - } |
124 | | - if let Some(seen_at) = seen_at { |
125 | | - graph.append(self.graph.insert_seen_at(txid, seen_at)); |
126 | | - } |
127 | | - |
| 106 | + pub fn insert_tx(&mut self, tx: Transaction) -> ChangeSet<A, I::ChangeSet> { |
| 107 | + let graph = self.graph.insert_tx(tx); |
128 | 108 | let indexer = self.index_tx_graph_changeset(&graph); |
129 | 109 | ChangeSet { graph, indexer } |
130 | 110 | } |
131 | 111 |
|
| 112 | + /// Insert an `anchor` for a given transaction. |
| 113 | + pub fn insert_anchor(&mut self, txid: Txid, anchor: A) -> ChangeSet<A, I::ChangeSet> { |
| 114 | + self.graph.insert_anchor(txid, anchor).into() |
| 115 | + } |
| 116 | + |
| 117 | + /// Insert a unix timestamp of when a transaction is seen in the mempool. |
| 118 | + /// |
| 119 | + /// This is used for transaction conflict resolution in [`TxGraph`] where the transaction with |
| 120 | + /// the later last-seen is prioritized. |
| 121 | + pub fn insert_seen_at(&mut self, txid: Txid, seen_at: u64) -> ChangeSet<A, I::ChangeSet> { |
| 122 | + self.graph.insert_seen_at(txid, seen_at).into() |
| 123 | + } |
| 124 | + |
132 | 125 | /// Batch insert transactions, filtering out those that are irrelevant. |
133 | 126 | /// |
134 | 127 | /// Relevancy is determined by the [`Indexer::is_tx_relevant`] implementation of `I`. Irrelevant |
|
0 commit comments