From ae0ba6c1356505697fc5e841741ac488538e3407 Mon Sep 17 00:00:00 2001 From: jrakibi Date: Tue, 4 Mar 2025 22:49:28 +0700 Subject: [PATCH] Take spent closure by value in count_witness_sigops and count_p2sh_sigops This fixes issue #4141 Change count_witness_sigops and count_p2sh_sigops to take the spent closure by value instead of &mut - Changed both functions to accept S as a value (FnMut) instead of &mut S - Removes need to annotate &mut when calling the function --- bitcoin/src/blockdata/transaction.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 9a3707d5d..e1401eb72 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -414,7 +414,7 @@ impl TransactionExt for Transaction { // coinbase tx is correctly handled because `spent` will always returns None. cost = cost.saturating_add(self.count_p2sh_sigops(&mut spent).saturating_mul(4)); - cost.saturating_add(self.count_witness_sigops(&mut spent)) + cost.saturating_add(self.count_witness_sigops(spent)) } #[inline] @@ -453,12 +453,12 @@ trait TransactionExtPriv { fn count_p2pk_p2pkh_sigops(&self) -> usize; /// Does not include wrapped SegWit (see `count_witness_sigops`). - fn count_p2sh_sigops(&self, spent: &mut S) -> usize + fn count_p2sh_sigops(&self, spent: S) -> usize where S: FnMut(&OutPoint) -> Option; /// Includes wrapped SegWit (returns 0 for Taproot spends). - fn count_witness_sigops(&self, spent: &mut S) -> usize + fn count_witness_sigops(&self, spent: S) -> usize where S: FnMut(&OutPoint) -> Option; @@ -481,7 +481,7 @@ impl TransactionExtPriv for Transaction { } /// Does not include wrapped SegWit (see `count_witness_sigops`). - fn count_p2sh_sigops(&self, spent: &mut S) -> usize + fn count_p2sh_sigops(&self, mut spent: S) -> usize where S: FnMut(&OutPoint) -> Option, { @@ -506,7 +506,7 @@ impl TransactionExtPriv for Transaction { } /// Includes wrapped SegWit (returns 0 for Taproot spends). - fn count_witness_sigops(&self, spent: &mut S) -> usize + fn count_witness_sigops(&self, mut spent: S) -> usize where S: FnMut(&OutPoint) -> Option, {