Skip to content

Commit 236e5c3

Browse files
committed
add remove_partial_sigs to SignOptions
1 parent 17d0ae0 commit 236e5c3

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Signing Taproot PSBTs (key spend and script spend)
2323
- Support for `tr()` descriptors in the `descriptor!()` macro
2424
- Add support for Bitcoin Core 23.0 when using the `rpc` blockchain
25+
- Add `remove_partial_sigs` to `SignOptions`
2526

2627
## [v0.18.0] - [v0.17.0]
2728

src/wallet/mod.rs

+38
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ where
11611161
let psbt_input = &mut psbt.inputs[n];
11621162
psbt_input.final_script_sig = Some(tmp_input.script_sig);
11631163
psbt_input.final_script_witness = Some(tmp_input.witness);
1164+
if sign_options.remove_partial_sigs {
1165+
psbt_input.partial_sigs.clear();
1166+
}
11641167
}
11651168
Err(e) => {
11661169
debug!("satisfy error {:?} for input {}", e, n);
@@ -1745,6 +1748,15 @@ pub(crate) mod test {
17451748
use crate::signer::{SignOptions, SignerError};
17461749
use crate::wallet::AddressIndex::{LastUnused, New, Peek, Reset};
17471750

1751+
fn create_drain_all_and_consolidate_psbt(
1752+
wallet: &Wallet<AnyDatabase>,
1753+
) -> psbt::PartiallySignedTransaction {
1754+
let addr = wallet.get_address(New).unwrap();
1755+
let mut builder = wallet.build_tx();
1756+
builder.drain_to(addr.script_pubkey()).drain_wallet();
1757+
builder.finish().unwrap().0
1758+
}
1759+
17481760
#[test]
17491761
fn test_cache_addresses_fixed() {
17501762
let db = MemoryDatabase::new();
@@ -3878,6 +3890,32 @@ pub(crate) mod test {
38783890
)
38793891
}
38803892

3893+
#[test]
3894+
fn test_remove_partial_sigs_after_finalize_sign_option() {
3895+
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
3896+
3897+
for remove_partial_sigs in &[true, false] {
3898+
let mut psbt = create_drain_all_and_consolidate_psbt(&wallet);
3899+
assert!(wallet
3900+
.sign(
3901+
&mut psbt,
3902+
SignOptions {
3903+
remove_partial_sigs: *remove_partial_sigs,
3904+
..Default::default()
3905+
},
3906+
)
3907+
.unwrap());
3908+
3909+
psbt.inputs.iter().for_each(|input| {
3910+
if *remove_partial_sigs {
3911+
assert!(input.partial_sigs.is_empty())
3912+
} else {
3913+
assert!(!input.partial_sigs.is_empty())
3914+
}
3915+
});
3916+
}
3917+
}
3918+
38813919
#[test]
38823920
fn test_sign_nonstandard_sighash() {
38833921
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;

src/wallet/signer.rs

+5
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ pub struct SignOptions {
667667
///
668668
/// Defaults to `false` which will only allow signing using `SIGHASH_ALL`.
669669
pub allow_all_sighashes: bool,
670+
/// Whether to remove partial_sigs from psbt inputs while finalizing psbt.
671+
///
672+
/// Defaults to `true` which will remove partial_sigs after finalizing.
673+
pub remove_partial_sigs: bool,
670674
}
671675

672676
#[allow(clippy::derivable_impls)]
@@ -676,6 +680,7 @@ impl Default for SignOptions {
676680
trust_witness_utxo: false,
677681
assume_height: None,
678682
allow_all_sighashes: false,
683+
remove_partial_sigs: true,
679684
}
680685
}
681686
}

0 commit comments

Comments
 (0)