diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 57d822ad..003b5ac2 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -586,8 +586,12 @@ where .iter() .chain(self.change_signers.signers().iter()) { - for index in 0..psbt.inputs.len() { - signer.sign(&mut psbt, index)?; + if signer.sign_whole_tx() { + signer.sign(&mut psbt, None)?; + } else { + for index in 0..psbt.inputs.len() { + signer.sign(&mut psbt, Some(index))?; + } } } diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index d94589c1..9744a628 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -1,4 +1,3 @@ -use std::any::Any; use std::cmp::Ordering; use std::collections::BTreeMap; use std::fmt; @@ -66,9 +65,13 @@ pub trait Signer: fmt::Debug { fn sign( &self, psbt: &mut psbt::PartiallySignedTransaction, - input_index: usize, + input_index: Option, ) -> Result<(), SignerError>; + fn sign_whole_tx(&self) -> bool { + false + } + fn descriptor_secret_key(&self) -> Option { None } @@ -78,8 +81,9 @@ impl Signer for DescriptorXKey { fn sign( &self, psbt: &mut psbt::PartiallySignedTransaction, - input_index: usize, + input_index: Option, ) -> Result<(), SignerError> { + let input_index = input_index.unwrap(); if input_index >= psbt.inputs.len() { return Err(SignerError::InputIndexOutOfRange); } @@ -97,7 +101,7 @@ impl Signer for DescriptorXKey { let ctx = Secp256k1::signing_only(); let derived_key = self.xkey.derive_priv(&ctx, &deriv_path).unwrap(); - derived_key.private_key.sign(psbt, input_index) + derived_key.private_key.sign(psbt, Some(input_index)) } fn descriptor_secret_key(&self) -> Option { @@ -109,8 +113,9 @@ impl Signer for PrivateKey { fn sign( &self, psbt: &mut psbt::PartiallySignedTransaction, - input_index: usize, + input_index: Option, ) -> Result<(), SignerError> { + let input_index = input_index.unwrap(); if input_index >= psbt.inputs.len() { return Err(SignerError::InputIndexOutOfRange); } @@ -192,20 +197,6 @@ impl SignersContainer { } } -impl Signer for SignersContainer { - fn sign( - &self, - psbt: &mut psbt::PartiallySignedTransaction, - input_index: usize, - ) -> Result<(), SignerError> { - for signer in self.0.values() { - signer.sign(psbt, input_index)?; - } - - Ok(()) - } -} - impl From for SignersContainer { fn from(keymap: KeyMap) -> SignersContainer { let mut container = SignersContainer::new();