]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Switch from slice to slice-of-refs for spend_spendable_outputs
authorMatt Corallo <git@bluematt.me>
Fri, 19 Feb 2021 18:08:54 +0000 (13:08 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 19 Feb 2021 18:58:05 +0000 (13:58 -0500)
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
lightning/src/ln/functional_tests.rs

index b3e33b57ca8e0ff3282c85f075f12c6bbc81f080..37d4c744ccd9fce7115f5ab1e2e7735c5da80ca5 100644 (file)
@@ -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<C: Signing>(&self, descriptors: &[SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: Script, feerate_sat_per_1000_weight: u32, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
+       pub fn spend_spendable_outputs<C: Signing>(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec<TxOut>, change_destination_script: Script, feerate_sat_per_1000_weight: u32, secp_ctx: &Secp256k1<C>) -> Result<Transaction, ()> {
                let mut input = Vec::new();
                let mut input_value = 0;
                let mut witness_weight = 0;
index 16212f9272f98201dd40bf0406dd4af7fc959f30..2060b952ddf19260a121c7259c92acafd401aa10 100644 (file)
@@ -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<_>>(), Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, &secp_ctx) {
                                        txn.push(tx);
                                }
                        }