From: 志宇 Date: Tue, 30 Apr 2024 06:49:03 +0000 (+0800) Subject: feat(chain): `TxGraph::insert_tx` reuses `Arc` X-Git-Tag: v1.0.0-alpha.11~1^2~11 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.CommandStringError.html?a=commitdiff_plain;h=e3cfb84898cfa79d4903cf276fc69ffb0605b4d4;p=bdk feat(chain): `TxGraph::insert_tx` reuses `Arc` When we insert a transaction that is already wrapped in `Arc`, we should reuse the `Arc`. --- diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index cf514855..d097b8fa 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -516,12 +516,12 @@ impl TxGraph { /// 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 { + pub fn insert_tx>>(&mut self, tx: T) -> ChangeSet { + 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) }