//! [`IndexedTxGraph`] documentation for more.
use core::fmt::Debug;
-use alloc::vec::Vec;
+use alloc::{sync::Arc, vec::Vec};
use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid};
use crate::{
}
/// Insert and index a transaction into the graph.
- pub fn insert_tx(&mut self, tx: Transaction) -> ChangeSet<A, I::ChangeSet> {
- let graph = self.graph.insert_tx(tx);
- let indexer = self.index_tx_graph_changeset(&graph);
- ChangeSet {
- tx_graph: graph,
- indexer,
- }
+ pub fn insert_tx<T: Into<Arc<Transaction>>>(&mut self, tx: T) -> ChangeSet<A, I::ChangeSet> {
+ let tx_graph = self.graph.insert_tx(tx);
+ let indexer = self.index_tx_graph_changeset(&tx_graph);
+ ChangeSet { tx_graph, indexer }
}
/// Insert an `anchor` for a given transaction.
/// To filter out irrelevant transactions, use [`batch_insert_relevant_unconfirmed`] instead.
///
/// [`batch_insert_relevant_unconfirmed`]: IndexedTxGraph::batch_insert_relevant_unconfirmed
- pub fn batch_insert_unconfirmed(
+ pub fn batch_insert_unconfirmed<T: Into<Arc<Transaction>>>(
&mut self,
- txs: impl IntoIterator<Item = (Transaction, u64)>,
+ txs: impl IntoIterator<Item = (T, u64)>,
) -> ChangeSet<A, I::ChangeSet> {
let graph = self.graph.batch_insert_unconfirmed(txs);
let indexer = self.index_tx_graph_changeset(&graph);
/// Items of `txs` are tuples containing the transaction and a *last seen* timestamp. The
/// *last seen* communicates when the transaction is last seen in mempool which is used for
/// conflict-resolution (refer to [`TxGraph::insert_seen_at`] for details).
- pub fn batch_insert_unconfirmed(
+ pub fn batch_insert_unconfirmed<T: Into<Arc<Transaction>>>(
&mut self,
- txs: impl IntoIterator<Item = (Transaction, u64)>,
+ txs: impl IntoIterator<Item = (T, u64)>,
) -> ChangeSet<A> {
let mut changeset = ChangeSet::<A>::default();
for (tx, seen_at) in txs {
+ let tx: Arc<Transaction> = tx.into();
changeset.merge(self.insert_seen_at(tx.compute_txid(), seen_at));
changeset.merge(self.insert_tx(tx));
}