]> Untitled Git - bdk/commitdiff
refactor(chain): compute txid once for `KeychainTxOutIndex::index_tx`
author志宇 <hello@evanlinjin.me>
Thu, 13 Jun 2024 14:56:19 +0000 (22:56 +0800)
committer志宇 <hello@evanlinjin.me>
Thu, 13 Jun 2024 15:03:34 +0000 (23:03 +0800)
crates/chain/src/keychain/txout_index.rs

index 0bdd6c94f00e6c756cca057aca18a0aceb441a88..cf0f21f881709146237e54c74fab72671e6c8879 100644 (file)
@@ -154,8 +154,9 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
 
     fn index_tx(&mut self, tx: &bitcoin::Transaction) -> Self::ChangeSet {
         let mut changeset = ChangeSet::<K>::default();
+        let txid = tx.compute_txid();
         for (op, txout) in tx.output.iter().enumerate() {
-            changeset.append(self.index_txout(OutPoint::new(tx.compute_txid(), op as u32), txout));
+            changeset.append(self.index_txout(OutPoint::new(txid, op as u32), txout));
         }
         changeset
     }