From 7442548263d52b6816b10748ad32cfe277862512 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 27 Mar 2024 12:08:40 +0100 Subject: [PATCH] Move `input_idx` retrieval into closure --- lightning/src/sign/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index b1d876b3e..5c895fbc4 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -1539,9 +1539,10 @@ impl KeysManager { pub fn sign_spendable_outputs_psbt(&self, descriptors: &[&SpendableOutputDescriptor], mut psbt: PartiallySignedTransaction, secp_ctx: &Secp256k1) -> Result { let mut keys_cache: Option<(InMemorySigner, [u8; 32])> = None; for outp in descriptors { + let get_input_idx = |outpoint: &OutPoint| psbt.unsigned_tx.input.iter().position(|i| i.previous_output == outpoint.into_bitcoin_outpoint()).ok_or(()); match outp { SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => { - let input_idx = psbt.unsigned_tx.input.iter().position(|i| i.previous_output == descriptor.outpoint.into_bitcoin_outpoint()).ok_or(())?; + let input_idx = get_input_idx(&descriptor.outpoint)?; if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id { let mut signer = self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id); if let Some(channel_params) = descriptor.channel_transaction_parameters.as_ref() { @@ -1553,7 +1554,7 @@ impl KeysManager { psbt.inputs[input_idx].final_script_witness = Some(witness); }, SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => { - let input_idx = psbt.unsigned_tx.input.iter().position(|i| i.previous_output == descriptor.outpoint.into_bitcoin_outpoint()).ok_or(())?; + let input_idx = get_input_idx(&descriptor.outpoint)?; if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id { keys_cache = Some(( self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id), @@ -1563,7 +1564,7 @@ impl KeysManager { psbt.inputs[input_idx].final_script_witness = Some(witness); }, SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output, .. } => { - let input_idx = psbt.unsigned_tx.input.iter().position(|i| i.previous_output == outpoint.into_bitcoin_outpoint()).ok_or(())?; + let input_idx = get_input_idx(outpoint)?; let derivation_idx = if output.script_pubkey == self.destination_script { 1 } else { -- 2.39.5