[wallet] Support signing the whole tx instead of individual inputs

This commit is contained in:
Alekos Filini 2020-08-17 23:50:50 +02:00
parent 991db28170
commit ff50087de5
No known key found for this signature in database
GPG Key ID: 5E8AFC3034FDFA4F
2 changed files with 16 additions and 21 deletions

View File

@ -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))?;
}
}
}

View File

@ -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<usize>,
) -> Result<(), SignerError>;
fn sign_whole_tx(&self) -> bool {
false
}
fn descriptor_secret_key(&self) -> Option<DescriptorSecretKey> {
None
}
@ -78,8 +81,9 @@ impl Signer for DescriptorXKey<ExtendedPrivKey> {
fn sign(
&self,
psbt: &mut psbt::PartiallySignedTransaction,
input_index: usize,
input_index: Option<usize>,
) -> 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<ExtendedPrivKey> {
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<DescriptorSecretKey> {
@ -109,8 +113,9 @@ impl Signer for PrivateKey {
fn sign(
&self,
psbt: &mut psbt::PartiallySignedTransaction,
input_index: usize,
input_index: Option<usize>,
) -> Result<(), SignerError> {
let input_index = input_index.unwrap();
if input_index >= psbt.inputs.len() {
return Err(SignerError::InputIndexOutOfRange);
}
@ -192,20 +197,6 @@ impl SignersContainer<DescriptorPublicKey> {
}
}
impl<Pk: MiniscriptKey + Any> Signer for SignersContainer<Pk> {
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<KeyMap> for SignersContainer<DescriptorPublicKey> {
fn from(keymap: KeyMap) -> SignersContainer<DescriptorPublicKey> {
let mut container = SignersContainer::new();