Merge rust-bitcoin/rust-bitcoin#4197: Take `spent` closure by value in `count_witness_sigops`

ae0ba6c135 Take spent closure by value in count_witness_sigops and count_p2sh_sigops (jrakibi)

Pull request description:

  This fixes #4141

  Changed `count_witness_sigops` to take the `spent` closure by value instead of `&mut`
  This removes the need for `&mut` when calling the function while still allowing mutable closure to be passed when needed

ACKs for top commit:
  Kixunil:
    ACK ae0ba6c135
  tcharding:
    ACK ae0ba6c135
  apoelstra:
    ACK ae0ba6c1356505697fc5e841741ac488538e3407; successfully ran local tests

Tree-SHA512: 76c5c98994b00412d0d371c07e3e83538f21754129a67889c66e1299e0453defaecb82bd4305297f772d65b042045d3579eaac14f8ea59419bf26b8b0d2ac84f
This commit is contained in:
merge-script 2025-03-08 01:25:53 +00:00
commit a959df3edf
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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>,
{