From 2f06b53abf602056936d5937d99eca45226a52e2 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 19 Feb 2021 13:08:54 -0500 Subject: [PATCH] Switch from slice to slice-of-refs for spend_spendable_outputs Sadly, there's just not really a practical way to map a slice of objects in our current bindings infrastructure - either we take ownership of the underlying objects and move them into a Vec, or we need to leave the original objects in place and have a list of pointers to the Rust objects. Thus, the only practical mapping is to create a slice of references using the pointers we have. --- lightning/src/chain/keysinterface.rs | 2 +- lightning/src/ln/functional_tests.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index b3e33b57c..37d4c744c 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -884,7 +884,7 @@ impl KeysManager { /// /// May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used /// this KeysManager or one of the `InMemoryChannelKeys` created by this KeysManager. - pub fn spend_spendable_outputs(&self, descriptors: &[SpendableOutputDescriptor], outputs: Vec, change_destination_script: Script, feerate_sat_per_1000_weight: u32, secp_ctx: &Secp256k1) -> Result { + pub fn spend_spendable_outputs(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec, change_destination_script: Script, feerate_sat_per_1000_weight: u32, secp_ctx: &Secp256k1) -> Result { let mut input = Vec::new(); let mut input_value = 0; let mut witness_weight = 0; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 16212f927..2060b952d 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -4659,16 +4659,15 @@ macro_rules! check_spendable_outputs { match event { Event::SpendableOutputs { mut outputs } => { for outp in outputs.drain(..) { - let mut outputs = vec![outp]; - txn.push($keysinterface.backing.spend_spendable_outputs(&outputs, Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, &secp_ctx).unwrap()); - all_outputs.push(outputs.pop().unwrap()); + txn.push($keysinterface.backing.spend_spendable_outputs(&[&outp], Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, &secp_ctx).unwrap()); + all_outputs.push(outp); } }, _ => panic!("Unexpected event"), }; } if all_outputs.len() > 1 { - if let Ok(tx) = $keysinterface.backing.spend_spendable_outputs(&all_outputs, Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, &secp_ctx) { + if let Ok(tx) = $keysinterface.backing.spend_spendable_outputs(&all_outputs.iter().map(|a| a).collect::>(), Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, &secp_ctx) { txn.push(tx); } } -- 2.39.5