@@ -17,6 +17,7 @@ pub use error::{BuildSenderError, ResponseError, ValidationError, WellKnownError
1717pub ( crate ) use error:: { InternalBuildSenderError , InternalProposalError , InternalValidationError } ;
1818use url:: Url ;
1919
20+ use crate :: output_substitution:: OutputSubstitution ;
2021use crate :: psbt:: PsbtExt ;
2122
2223// See usize casts
@@ -51,7 +52,7 @@ pub(crate) struct AdditionalFeeContribution {
5152#[ derive( Debug , Clone ) ]
5253pub struct PsbtContext {
5354 original_psbt : Psbt ,
54- disable_output_substitution : bool ,
55+ output_substitution : OutputSubstitution ,
5556 fee_contribution : Option < AdditionalFeeContribution > ,
5657 min_fee_rate : FeeRate ,
5758 payee : ScriptBuf ,
@@ -253,7 +254,7 @@ impl PsbtContext {
253254 if original_output. script_pubkey == self . payee =>
254255 {
255256 ensure ! (
256- ! self . disable_output_substitution
257+ self . output_substitution == OutputSubstitution :: Enabled
257258 || ( proposed_txout. script_pubkey == original_output. script_pubkey
258259 && proposed_txout. value >= original_output. value) ,
259260 DisallowedOutputSubstitution
@@ -414,14 +415,14 @@ fn determine_fee_contribution(
414415
415416fn serialize_url (
416417 endpoint : Url ,
417- disable_output_substitution : bool ,
418+ output_substitution : OutputSubstitution ,
418419 fee_contribution : Option < AdditionalFeeContribution > ,
419420 min_fee_rate : FeeRate ,
420421 version : & str ,
421422) -> Url {
422423 let mut url = endpoint;
423424 url. query_pairs_mut ( ) . append_pair ( "v" , version) ;
424- if disable_output_substitution {
425+ if output_substitution == OutputSubstitution :: Disabled {
425426 url. query_pairs_mut ( ) . append_pair ( "disableoutputsubstitution" , "true" ) ;
426427 }
427428 if let Some ( AdditionalFeeContribution { max_amount, vout } ) = fee_contribution {
@@ -449,14 +450,15 @@ mod test {
449450 use super :: {
450451 check_single_payee, clear_unneeded_fields, determine_fee_contribution, serialize_url,
451452 } ;
453+ use crate :: output_substitution:: OutputSubstitution ;
452454 use crate :: psbt:: PsbtExt ;
453455 use crate :: send:: { AdditionalFeeContribution , InternalBuildSenderError , InternalProposalError } ;
454456
455457 pub ( crate ) fn create_psbt_context ( ) -> Result < super :: PsbtContext , BoxError > {
456458 let payee = PARSED_ORIGINAL_PSBT . unsigned_tx . output [ 1 ] . script_pubkey . clone ( ) ;
457459 Ok ( super :: PsbtContext {
458460 original_psbt : PARSED_ORIGINAL_PSBT . clone ( ) ,
459- disable_output_substitution : false ,
461+ output_substitution : OutputSubstitution :: Enabled ,
460462 fee_contribution : Some ( AdditionalFeeContribution {
461463 max_amount : bitcoin:: Amount :: from_sat ( 182 ) ,
462464 vout : 0 ,
@@ -641,10 +643,22 @@ mod test {
641643
642644 #[ test]
643645 fn test_disable_output_substitution_query_param ( ) -> Result < ( ) , BoxError > {
644- let url = serialize_url ( Url :: parse ( "http://localhost" ) ?, true , None , FeeRate :: ZERO , "2" ) ;
646+ let url = serialize_url (
647+ Url :: parse ( "http://localhost" ) ?,
648+ OutputSubstitution :: Disabled ,
649+ None ,
650+ FeeRate :: ZERO ,
651+ "2" ,
652+ ) ;
645653 assert_eq ! ( url, Url :: parse( "http://localhost?v=2&disableoutputsubstitution=true" ) ?) ;
646654
647- let url = serialize_url ( Url :: parse ( "http://localhost" ) ?, false , None , FeeRate :: ZERO , "2" ) ;
655+ let url = serialize_url (
656+ Url :: parse ( "http://localhost" ) ?,
657+ OutputSubstitution :: Enabled ,
658+ None ,
659+ FeeRate :: ZERO ,
660+ "2" ,
661+ ) ;
648662 assert_eq ! ( url, Url :: parse( "http://localhost?v=2" ) ?) ;
649663 Ok ( ( ) )
650664 }
0 commit comments