diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 7e90c4425..f0c755e50 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -501,8 +501,8 @@ impl Transaction { /// This is useful in combination with [`predict_weight`] if you have the transaction already /// constructed with a dummy value in the fee output which you'll adjust after calculating the /// weight. - pub fn script_pubkey_lens(&self) -> impl Iterator + '_ { - self.output.iter().map(|txout| txout.script_pubkey.len()) + pub fn script_pubkey_lens(&self) -> TxOutToScriptPubkeyLengthIter { + TxOutToScriptPubkeyLengthIter { inner: self.output.iter() } } /// Counts the total number of sigops. @@ -545,6 +545,18 @@ impl Transaction { } } +/// Iterates over transaction outputs and for each output yields the length of the scriptPubkey. +// This exists to hardcode the type of the closure crated by `map`. +pub struct TxOutToScriptPubkeyLengthIter<'a> { + inner: core::slice::Iter<'a, TxOut>, +} + +impl Iterator for TxOutToScriptPubkeyLengthIter<'_> { + type Item = usize; + + fn next(&mut self) -> Option { self.inner.next().map(|txout| txout.script_pubkey.len()) } +} + impl Transaction { /// Gets the sigop count. ///