From: vmammal Date: Sun, 29 Oct 2023 03:12:22 +0000 (-0400) Subject: ref(psbt): refactor body of `get_utxo_for` to address `clippy::manual_map` X-Git-Tag: v1.0.0-alpha.6~6^2~3 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/struct.EncoderStringWriter.html?a=commitdiff_plain;h=f11d663b7efb98dd72fed903ade8c5e7af0b5a3a;p=bdk ref(psbt): refactor body of `get_utxo_for` to address `clippy::manual_map` --- diff --git a/crates/bdk/src/psbt/mod.rs b/crates/bdk/src/psbt/mod.rs index bc6ce858..796b8618 100644 --- a/crates/bdk/src/psbt/mod.rs +++ b/crates/bdk/src/psbt/mod.rs @@ -35,24 +35,16 @@ pub trait PsbtUtils { } impl PsbtUtils for Psbt { - #[allow(clippy::all)] // We want to allow `manual_map` but it is too new. fn get_utxo_for(&self, input_index: usize) -> Option { let tx = &self.unsigned_tx; + let input = self.inputs.get(input_index)?; - if input_index >= tx.input.len() { - return None; - } - - if let Some(input) = self.inputs.get(input_index) { - if let Some(wit_utxo) = &input.witness_utxo { - Some(wit_utxo.clone()) - } else if let Some(in_tx) = &input.non_witness_utxo { - Some(in_tx.output[tx.input[input_index].previous_output.vout as usize].clone()) - } else { - None - } - } else { - None + match (&input.witness_utxo, &input.non_witness_utxo) { + (Some(_), _) => input.witness_utxo.clone(), + (_, Some(_)) => input.non_witness_utxo.as_ref().map(|in_tx| { + in_tx.output[tx.input[input_index].previous_output.vout as usize].clone() + }), + _ => None, } }