@@ -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,34 @@ 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_1 = create_drain_all_and_consolidate_psbt ( & wallet) ;
3899+ assert ! ( wallet
3900+ . sign(
3901+ & mut psbt_1,
3902+ SignOptions {
3903+ remove_partial_sigs: * remove_partial_sigs,
3904+ ..Default :: default ( )
3905+ } ,
3906+ )
3907+ . unwrap( ) ) ;
3908+
3909+ psbt_1. inputs . iter ( ) . for_each ( |input| {
3910+ // remove finalized input partial_sigs if remove_partial_sigs is set as true in SignOptions
3911+ // do not remove finalized input partial_sigs if remove_partial_sigs is set as false in SignOptions.
3912+ if * remove_partial_sigs {
3913+ assert ! ( input. partial_sigs. is_empty( ) )
3914+ } else {
3915+ assert ! ( !input. partial_sigs. is_empty( ) )
3916+ }
3917+ } ) ;
3918+ }
3919+ }
3920+
38813921 #[ test]
38823922 fn test_sign_nonstandard_sighash ( ) {
38833923 let sighash = EcdsaSighashType :: NonePlusAnyoneCanPay ;
0 commit comments