Skip to content

Commit 9995830

Browse files
committed
add do_not_remove_partial_sigs to SignOptions
1 parent fbd98b4 commit 9995830

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add traits to reuse `Blockchain`s across multiple wallets (`BlockchainFactory` and `StatelessBlockchain`).
1313
- Upgrade to rust-bitcoin `0.28`
1414
- If using the `sqlite-db` feature all cached wallet data is deleted due to a possible UTXO inconsistency, a wallet.sync will recreate it
15+
- Added `do_not_remove_partial_sigs` to `SignOptions`
1516

1617
## [v0.18.0] - [v0.17.0]
1718

src/wallet/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ where
11571157
let psbt_input = &mut psbt.inputs[n];
11581158
psbt_input.final_script_sig = Some(tmp_input.script_sig);
11591159
psbt_input.final_script_witness = Some(tmp_input.witness);
1160+
if !sign_options.do_not_remove_partial_sigs {
1161+
psbt_input.partial_sigs.clear();
1162+
}
11601163
}
11611164
Err(e) => {
11621165
debug!("satisfy error {:?} for input {}", e, n);
@@ -3785,6 +3788,54 @@ pub(crate) mod test {
37853788
)
37863789
}
37873790

3791+
#[test]
3792+
fn test_do_not_remove_partial_sigs_after_finalize_sign_option() {
3793+
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
3794+
3795+
fn create_psbt(wallet: &Wallet<AnyDatabase>) -> psbt::PartiallySignedTransaction {
3796+
let addr = wallet.get_address(New).unwrap();
3797+
let mut builder = wallet.build_tx();
3798+
builder.drain_to(addr.script_pubkey()).drain_wallet();
3799+
builder.finish().unwrap().0
3800+
}
3801+
3802+
// remove finalized input partial_sigs if do_not_remove_partial_sigs is set as false in SignOptions
3803+
let mut psbt_1 = create_psbt(&wallet);
3804+
3805+
assert!(wallet
3806+
.sign(
3807+
&mut psbt_1,
3808+
SignOptions {
3809+
do_not_remove_partial_sigs: false,
3810+
..Default::default()
3811+
},
3812+
)
3813+
.unwrap());
3814+
3815+
psbt_1
3816+
.inputs
3817+
.iter()
3818+
.for_each(|input| assert!(input.partial_sigs.is_empty()));
3819+
3820+
// do not remove finalized input partial_sigs if do_not_remove_partial_sigs is set as true in SignOptions
3821+
let mut psbt_2 = create_psbt(&wallet);
3822+
3823+
assert!(!wallet
3824+
.sign(
3825+
&mut psbt_2,
3826+
SignOptions {
3827+
do_not_remove_partial_sigs: true,
3828+
..Default::default()
3829+
},
3830+
)
3831+
.unwrap());
3832+
3833+
psbt_2
3834+
.inputs
3835+
.iter()
3836+
.for_each(|input| assert!(!input.partial_sigs.is_empty()));
3837+
}
3838+
37883839
#[test]
37893840
fn test_sign_nonstandard_sighash() {
37903841
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;

src/wallet/signer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,11 @@ pub struct SignOptions {
492492
/// Whether the signer should use the `sighash_type` set in the PSBT when signing, no matter
493493
/// what its value is
494494
///
495-
/// Defaults to `false` which will only allow signing using `SIGHASH_ALL`.
495+
/// Defaults to `false` which will remove partial_sigs after input is signed
496496
pub allow_all_sighashes: bool,
497+
/// Whether partial_sigs in input should be removed when the psbt_input is signed in finalizing psbt.
498+
/// Defaults to `false` which will partial_sigs will be removed after signing.
499+
pub do_not_remove_partial_sigs: bool,
497500
}
498501

499502
#[allow(clippy::derivable_impls)]
@@ -503,6 +506,7 @@ impl Default for SignOptions {
503506
trust_witness_utxo: false,
504507
assume_height: None,
505508
allow_all_sighashes: false,
509+
do_not_remove_partial_sigs: false,
506510
}
507511
}
508512
}

0 commit comments

Comments
 (0)