88//! `https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki`
99//!
1010
11+ use core:: mem;
12+
1113use bitcoin:: hashes:: hash160;
1214use bitcoin:: key:: XOnlyPublicKey ;
1315use bitcoin:: secp256k1:: { self , Secp256k1 } ;
@@ -415,8 +417,10 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
415417 // Now mutate the psbt input. Note that we cannot error after this point.
416418 // If the input is mutated, it means that the finalization succeeded.
417419 {
420+ let original = mem:: replace ( & mut psbt. inputs [ index] , Default :: default ( ) ) ;
418421 let input = & mut psbt. inputs [ index] ;
419- //Fill in the satisfactions
422+ input. non_witness_utxo = original. non_witness_utxo ;
423+ input. witness_utxo = original. witness_utxo ;
420424 input. final_script_sig = if script_sig. is_empty ( ) {
421425 None
422426 } else {
@@ -427,25 +431,6 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
427431 } else {
428432 Some ( witness)
429433 } ;
430- //reset everything
431- input. partial_sigs . clear ( ) ; // 0x02
432- input. sighash_type = None ; // 0x03
433- input. redeem_script = None ; // 0x04
434- input. witness_script = None ; // 0x05
435- input. bip32_derivation . clear ( ) ; // 0x05
436- // finalized witness 0x06 and 0x07 are not clear
437- // 0x09 Proof of reserves not yet supported
438- input. ripemd160_preimages . clear ( ) ; // 0x0a
439- input. sha256_preimages . clear ( ) ; // 0x0b
440- input. hash160_preimages . clear ( ) ; // 0x0c
441- input. hash256_preimages . clear ( ) ; // 0x0d
442- // psbt v2 fields till 0x012 not supported
443- input. tap_key_sig = None ; // 0x013
444- input. tap_script_sigs . clear ( ) ; // 0x014
445- input. tap_scripts . clear ( ) ; // 0x015
446- input. tap_key_origins . clear ( ) ; // 0x16
447- input. tap_internal_key = None ; // x017
448- input. tap_merkle_root = None ; // 0x018
449434 }
450435
451436 Ok ( ( ) )
0 commit comments