File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919 - Signing Taproot PSBTs (key spend and script spend)
2020 - Support for ` tr() ` descriptors in the ` descriptor!() ` macro
2121- Add support for Bitcoin Core 23.0 when using the ` rpc ` blockchain
22- - Added ` remove_partial_sigs ` to ` SignOptions `
22+ - Added ` remove_partial_sigs ` and ` try_finalize ` to ` SignOptions `
2323
2424## [ v0.18.0] - [ v0.17.0]
2525
Original file line number Diff line number Diff line change @@ -1050,7 +1050,11 @@ where
10501050 }
10511051
10521052 // attempt to finalize
1053- self . finalize_psbt ( psbt, sign_options)
1053+ if sign_options. try_finalize {
1054+ self . finalize_psbt ( psbt, sign_options)
1055+ } else {
1056+ Ok ( false )
1057+ }
10541058 }
10551059
10561060 /// Return the spending policies for the wallet's descriptor
@@ -3916,6 +3920,37 @@ pub(crate) mod test {
39163920 }
39173921 }
39183922
3923+ #[ test]
3924+ fn test_try_finalize_sign_option ( ) {
3925+ let ( wallet, _, _) = get_funded_wallet ( "wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)" ) ;
3926+
3927+ for try_finalize in & [ true , false ] {
3928+ let mut psbt = create_drain_all_and_consolidate_psbt ( & wallet) ;
3929+
3930+ let finalized = wallet
3931+ . sign (
3932+ & mut psbt,
3933+ SignOptions {
3934+ try_finalize : * try_finalize,
3935+ ..Default :: default ( )
3936+ } ,
3937+ )
3938+ . unwrap ( ) ;
3939+
3940+ psbt. inputs . iter ( ) . for_each ( |input| {
3941+ if * try_finalize {
3942+ assert ! ( finalized) ;
3943+ assert ! ( input. final_script_sig. is_some( ) ) ;
3944+ assert ! ( input. final_script_witness. is_some( ) ) ;
3945+ } else {
3946+ assert ! ( !finalized) ;
3947+ assert ! ( input. final_script_sig. is_none( ) ) ;
3948+ assert ! ( input. final_script_witness. is_none( ) ) ;
3949+ }
3950+ } ) ;
3951+ }
3952+ }
3953+
39193954 #[ test]
39203955 fn test_sign_nonstandard_sighash ( ) {
39213956 let sighash = EcdsaSighashType :: NonePlusAnyoneCanPay ;
Original file line number Diff line number Diff line change @@ -671,6 +671,10 @@ pub struct SignOptions {
671671 ///
672672 /// Defaults to `true` which will remove partial_sigs after finalizing.
673673 pub remove_partial_sigs : bool ,
674+ /// Whether to try finalizing psbt input after the inputs are signed.
675+ ///
676+ /// Defaults to `true` which will try fianlizing psbt after inputs are signed.
677+ pub try_finalize : bool ,
674678}
675679
676680#[ allow( clippy:: derivable_impls) ]
@@ -681,6 +685,7 @@ impl Default for SignOptions {
681685 assume_height : None ,
682686 allow_all_sighashes : false ,
683687 remove_partial_sigs : true ,
688+ try_finalize : true ,
684689 }
685690 }
686691}
You can’t perform that action at this time.
0 commit comments