@@ -133,18 +133,26 @@ impl BitGoPsbt {
133133 BitGoPsbt :: Zcash ( zcash_psbt, _network) => Ok ( zcash_psbt. serialize ( ) ?) ,
134134 }
135135 }
136+
137+ pub fn into_psbt ( self ) -> Psbt {
138+ match self {
139+ BitGoPsbt :: BitcoinLike ( psbt, _network) => psbt,
140+ BitGoPsbt :: Zcash ( zcash_psbt, _network) => zcash_psbt. into_bitcoin_psbt ( ) ,
141+ }
142+ }
136143}
137144
138145#[ cfg( test) ]
139146mod tests {
140147 use super :: * ;
148+ use crate :: fixed_script_wallet:: Chain ;
141149 use crate :: fixed_script_wallet:: { RootWalletKeys , WalletScripts } ;
142150 use crate :: test_utils:: fixtures;
143- use crate :: fixed_script_wallet:: Chain ;
144151 use base64:: engine:: { general_purpose:: STANDARD as BASE64_STANDARD , Engine } ;
145152 use miniscript:: bitcoin:: bip32:: Xpub ;
146153 use miniscript:: bitcoin:: consensus:: Decodable ;
147154 use miniscript:: bitcoin:: Transaction ;
155+
148156 use std:: str:: FromStr ;
149157
150158 crate :: test_all_networks!( test_deserialize_invalid_bytes, network, {
@@ -531,6 +539,32 @@ mod tests {
531539 }
532540 ) ;
533541
542+ crate :: test_psbt_fixtures!( test_extract_transaction, network, {
543+ let fixture = fixtures:: load_psbt_fixture_with_format(
544+ network. to_utxolib_name( ) ,
545+ fixtures:: SignatureState :: Fullsigned ,
546+ fixtures:: TxFormat :: Psbt ,
547+ )
548+ . expect( "Failed to load fixture" ) ;
549+ let psbt = fixture
550+ . to_bitgo_psbt( network)
551+ . expect( "Failed to convert to BitGo PSBT" ) ;
552+ let fixture_extracted_transaction = fixture
553+ . extracted_transaction
554+ . expect( "Failed to extract transaction" ) ;
555+ let extracted_transaction = psbt
556+ . into_psbt( )
557+ . finalize( & crate :: bitcoin:: secp256k1:: Secp256k1 :: verification_only( ) )
558+ . expect( "Failed to finalize PSBT" )
559+ . extract_tx( )
560+ . expect( "Failed to extract transaction" ) ;
561+ let extracted_transaction_hex = hex:: encode( serialize( & extracted_transaction) ) ;
562+ assert_eq!(
563+ extracted_transaction_hex, fixture_extracted_transaction,
564+ "Extracted transaction should match"
565+ ) ;
566+ } ) ;
567+
534568 #[ test]
535569 fn test_serialize_bitcoin_psbt ( ) {
536570 // Test that Bitcoin-like PSBTs can be serialized
@@ -539,7 +573,9 @@ mod tests {
539573 fixtures:: SignatureState :: Unsigned ,
540574 )
541575 . unwrap ( ) ;
542- let psbt = fixture. to_bitgo_psbt ( Network :: Bitcoin ) . expect ( "Failed to convert to BitGo PSBT" ) ;
576+ let psbt = fixture
577+ . to_bitgo_psbt ( Network :: Bitcoin )
578+ . expect ( "Failed to convert to BitGo PSBT" ) ;
543579
544580 // Serialize should succeed
545581 let serialized = psbt. serialize ( ) ;
0 commit comments