From: Matt Corallo Date: Wed, 19 Jul 2023 19:37:21 +0000 (+0000) Subject: Tweak PSBT signing for bindings compatibility X-Git-Tag: v0.0.116~3^2~8 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0b9c5204afead590569453d4a910125cda8f27e3;p=rust-lightning Tweak PSBT signing for bindings compatibility In bindings we can't practically pass a mutable PSBT, and instead need to pass an owned transaction and have the sign method return a signed copy. We do this here for all build modes as its not a material API change for Rust users. --- diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index c11d47e9f..a71bdae88 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -1312,7 +1312,7 @@ impl KeysManager { /// /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`]. - pub fn sign_spendable_outputs_psbt(&self, descriptors: &[&SpendableOutputDescriptor], psbt: &mut PartiallySignedTransaction, secp_ctx: &Secp256k1) -> Result<(), ()> { + 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 { match outp { @@ -1374,7 +1374,7 @@ impl KeysManager { } } - Ok(()) + Ok(psbt) } /// Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an @@ -1396,7 +1396,7 @@ impl KeysManager { /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`]. pub fn spend_spendable_outputs(&self, descriptors: &[&SpendableOutputDescriptor], outputs: Vec, change_destination_script: Script, feerate_sat_per_1000_weight: u32, locktime: Option, secp_ctx: &Secp256k1) -> Result { let (mut psbt, expected_max_weight) = SpendableOutputDescriptor::create_spendable_outputs_psbt(descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime)?; - self.sign_spendable_outputs_psbt(descriptors, &mut psbt, secp_ctx)?; + psbt = self.sign_spendable_outputs_psbt(descriptors, psbt, secp_ctx)?; let spend_tx = psbt.extract_tx();