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
This commit is contained in:
jrakibi 2025-03-04 22:49:28 +07:00
parent 95c012ee53
commit ae0ba6c135
1 changed files with 5 additions and 5 deletions

View File

@ -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<S>(&self, spent: &mut S) -> usize
fn count_p2sh_sigops<S>(&self, spent: S) -> usize
where
S: FnMut(&OutPoint) -> Option<TxOut>;
/// Includes wrapped SegWit (returns 0 for Taproot spends).
fn count_witness_sigops<S>(&self, spent: &mut S) -> usize
fn count_witness_sigops<S>(&self, spent: S) -> usize
where
S: FnMut(&OutPoint) -> Option<TxOut>;
@ -481,7 +481,7 @@ impl TransactionExtPriv for Transaction {
}
/// Does not include wrapped SegWit (see `count_witness_sigops`).
fn count_p2sh_sigops<S>(&self, spent: &mut S) -> usize
fn count_p2sh_sigops<S>(&self, mut spent: S) -> usize
where
S: FnMut(&OutPoint) -> Option<TxOut>,
{
@ -506,7 +506,7 @@ impl TransactionExtPriv for Transaction {
}
/// Includes wrapped SegWit (returns 0 for Taproot spends).
fn count_witness_sigops<S>(&self, spent: &mut S) -> usize
fn count_witness_sigops<S>(&self, mut spent: S) -> usize
where
S: FnMut(&OutPoint) -> Option<TxOut>,
{