Skip to content

Commit e272a14

Browse files
committed
add do_not_finalize to SignOptions
1 parent 3afe89f commit e272a14

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Creation of Taproot PSBTs (BIP-371)
1919
- Signing Taproot PSBTs (key spend and script spend)
2020
- Support for `tr()` descriptors in the `descriptor!()` macro
21-
- Added `do_not_remove_partial_sigs` to `SignOptions`
21+
- Added `do_not_remove_partial_sigs` and `do_not_finalize` to `SignOptions`
2222

2323
## [v0.18.0] - [v0.17.0]
2424

src/wallet/mod.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,11 @@ where
10501050
}
10511051

10521052
// attempt to finalize
1053-
self.finalize_psbt(psbt, sign_options)
1053+
if sign_options.do_not_finalize {
1054+
Ok(false)
1055+
} else {
1056+
self.finalize_psbt(psbt, sign_options)
1057+
}
10541058
}
10551059

10561060
/// Return the spending policies for the wallet's descriptor
@@ -3931,6 +3935,48 @@ pub(crate) mod test {
39313935
.for_each(|input| assert!(!input.partial_sigs.is_empty()));
39323936
}
39333937

3938+
#[test]
3939+
fn test_do_not_finalize_sign_option() {
3940+
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
3941+
3942+
let mut psbt_1 = create_drain_all_and_consolidate_psbt(&wallet);
3943+
3944+
let finalized = wallet
3945+
.sign(
3946+
&mut psbt_1,
3947+
SignOptions {
3948+
do_not_finalize: false,
3949+
..Default::default()
3950+
},
3951+
)
3952+
.unwrap();
3953+
assert!(finalized);
3954+
3955+
psbt_1.inputs.iter().for_each(|input| {
3956+
assert!(input.final_script_sig.is_some());
3957+
assert!(input.final_script_witness.is_some());
3958+
});
3959+
3960+
// only sign and do not finalize if do_not_finalize is set as true in SignOptions
3961+
let mut psbt_2 = create_drain_all_and_consolidate_psbt(&wallet);
3962+
3963+
let finalized = wallet
3964+
.sign(
3965+
&mut psbt_2,
3966+
SignOptions {
3967+
do_not_finalize: true,
3968+
..Default::default()
3969+
},
3970+
)
3971+
.unwrap();
3972+
assert!(!finalized);
3973+
3974+
psbt_2.inputs.iter().for_each(|input| {
3975+
assert!(input.final_script_sig.is_none());
3976+
assert!(input.final_script_witness.is_none());
3977+
});
3978+
}
3979+
39343980
#[test]
39353981
fn test_sign_nonstandard_sighash() {
39363982
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;

src/wallet/signer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ pub struct SignOptions {
670670
/// Whether partial_sigs in input should be removed when the psbt_input is signed in finalizing psbt.
671671
/// Defaults to `false` which will partial_sigs will be removed after signing.
672672
pub do_not_remove_partial_sigs: bool,
673+
/// Whether the wallet should try to finalize psbt input should be removed when the psbt_input is signed after
674+
///
675+
/// Defaults to `false` which will partial_sigs after input is signed
676+
pub do_not_finalize: bool,
673677
}
674678

675679
#[allow(clippy::derivable_impls)]
@@ -680,6 +684,7 @@ impl Default for SignOptions {
680684
assume_height: None,
681685
allow_all_sighashes: false,
682686
do_not_remove_partial_sigs: false,
687+
do_not_finalize: false,
683688
}
684689
}
685690
}

0 commit comments

Comments
 (0)