feat(chain): TxGraph::insert_tx reuses Arc

When we insert a transaction that is already wrapped in `Arc`, we should
reuse the `Arc`.
This commit is contained in:
志宇 2024-04-30 14:49:03 +08:00
parent 2ffb65618a
commit e3cfb84898
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8

View File

@ -516,12 +516,12 @@ impl<A: Clone + Ord> TxGraph<A> {
/// Inserts the given transaction into [`TxGraph`].
///
/// The [`ChangeSet`] returned will be empty if `tx` already exists.
pub fn insert_tx(&mut self, tx: Transaction) -> ChangeSet<A> {
pub fn insert_tx<T: Into<Arc<Transaction>>>(&mut self, tx: T) -> ChangeSet<A> {
let tx = tx.into();
let mut update = Self::default();
update.txs.insert(
tx.txid(),
(TxNodeInternal::Whole(tx.into()), BTreeSet::new(), 0),
);
update
.txs
.insert(tx.txid(), (TxNodeInternal::Whole(tx), BTreeSet::new(), 0));
self.apply_update(update)
}