@@ -721,30 +721,25 @@ impl Receiver<MaybeInputsOwned> {
721721 Receiver < HasReplyableError > ,
722722 > {
723723 match self . state . original . check_inputs_not_owned ( is_owned) {
724- Ok ( inner) => inner,
724+ Ok ( ( ) ) => MaybeFatalTransition :: success (
725+ SessionEvent :: CheckedInputsNotOwned ( ) ,
726+ Receiver {
727+ state : MaybeInputsSeen { original : self . original . clone ( ) } ,
728+ session_context : self . session_context ,
729+ } ,
730+ ) ,
725731 Err ( e) => match e {
726- Error :: Implementation ( _) => {
727- return MaybeFatalTransition :: transient ( e) ;
728- }
729- _ => {
730- return MaybeFatalTransition :: replyable_error (
731- SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
732- Receiver {
733- state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
734- session_context : self . session_context ,
735- } ,
736- e,
737- ) ;
738- }
739- } ,
740- } ;
741- MaybeFatalTransition :: success (
742- SessionEvent :: CheckedInputsNotOwned ( ) ,
743- Receiver {
744- state : MaybeInputsSeen { original : self . original . clone ( ) } ,
745- session_context : self . session_context ,
732+ Error :: Implementation ( _) => MaybeFatalTransition :: transient ( e) ,
733+ _ => MaybeFatalTransition :: replyable_error (
734+ SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
735+ Receiver {
736+ state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
737+ session_context : self . session_context ,
738+ } ,
739+ e,
740+ ) ,
746741 } ,
747- )
742+ }
748743 }
749744
750745 pub ( crate ) fn apply_checked_inputs_not_owned ( self ) -> ReceiveSession {
@@ -783,30 +778,25 @@ impl Receiver<MaybeInputsSeen> {
783778 Receiver < HasReplyableError > ,
784779 > {
785780 match self . state . original . check_no_inputs_seen_before ( is_known) {
786- Ok ( inner) => inner,
781+ Ok ( ( ) ) => MaybeFatalTransition :: success (
782+ SessionEvent :: CheckedNoInputsSeenBefore ( ) ,
783+ Receiver {
784+ state : OutputsUnknown { original : self . original . clone ( ) } ,
785+ session_context : self . session_context ,
786+ } ,
787+ ) ,
787788 Err ( e) => match e {
788- Error :: Implementation ( _) => {
789- return MaybeFatalTransition :: transient ( e) ;
790- }
791- _ => {
792- return MaybeFatalTransition :: replyable_error (
793- SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
794- Receiver {
795- state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
796- session_context : self . session_context ,
797- } ,
798- e,
799- ) ;
800- }
801- } ,
802- } ;
803- MaybeFatalTransition :: success (
804- SessionEvent :: CheckedNoInputsSeenBefore ( ) ,
805- Receiver {
806- state : OutputsUnknown { original : self . original . clone ( ) } ,
807- session_context : self . session_context ,
789+ Error :: Implementation ( _) => MaybeFatalTransition :: transient ( e) ,
790+ _ => MaybeFatalTransition :: replyable_error (
791+ SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
792+ Receiver {
793+ state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
794+ session_context : self . session_context ,
795+ } ,
796+ e,
797+ ) ,
808798 } ,
809- )
799+ }
810800 }
811801
812802 pub ( crate ) fn apply_checked_no_inputs_seen_before ( self ) -> ReceiveSession {
@@ -849,28 +839,23 @@ impl Receiver<OutputsUnknown> {
849839 Error ,
850840 Receiver < HasReplyableError > ,
851841 > {
852- let inner = match self . state . original . identify_receiver_outputs ( is_receiver_output) {
853- Ok ( inner) => inner,
842+ match self . state . original . identify_receiver_outputs ( is_receiver_output) {
843+ Ok ( inner) => MaybeFatalTransition :: success (
844+ SessionEvent :: IdentifiedReceiverOutputs ( inner. owned_vouts . clone ( ) ) ,
845+ Receiver { state : WantsOutputs { inner } , session_context : self . session_context } ,
846+ ) ,
854847 Err ( e) => match e {
855- Error :: Implementation ( _) => {
856- return MaybeFatalTransition :: transient ( e) ;
857- }
858- _ => {
859- return MaybeFatalTransition :: replyable_error (
860- SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
861- Receiver {
862- state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
863- session_context : self . session_context ,
864- } ,
865- e,
866- ) ;
867- }
848+ Error :: Implementation ( _) => MaybeFatalTransition :: transient ( e) ,
849+ _ => MaybeFatalTransition :: replyable_error (
850+ SessionEvent :: GotReplyableError ( ( & e) . into ( ) ) ,
851+ Receiver {
852+ state : HasReplyableError { error_reply : ( & e) . into ( ) } ,
853+ session_context : self . session_context ,
854+ } ,
855+ e,
856+ ) ,
868857 } ,
869- } ;
870- MaybeFatalTransition :: success (
871- SessionEvent :: IdentifiedReceiverOutputs ( inner. owned_vouts . clone ( ) ) ,
872- Receiver { state : WantsOutputs { inner } , session_context : self . session_context } ,
873- )
858+ }
874859 }
875860
876861 pub ( crate ) fn apply_identified_receiver_outputs (
@@ -1054,23 +1039,20 @@ impl Receiver<WantsFeeRange> {
10541039 ) -> MaybeFatalTransition < SessionEvent , Receiver < ProvisionalProposal > , ProtocolError > {
10551040 let max_effective_fee_rate =
10561041 max_effective_fee_rate. or ( Some ( self . session_context . max_fee_rate ) ) ;
1057- let psbt_context = match self
1042+ match self
10581043 . state
10591044 . inner
10601045 . calculate_psbt_context_with_fee_range ( min_fee_rate, max_effective_fee_rate)
10611046 {
1062- Ok ( inner) => inner,
1063- Err ( e) => {
1064- return MaybeFatalTransition :: transient ( ProtocolError :: OriginalPayload ( e. into ( ) ) ) ;
1065- }
1066- } ;
1067- MaybeFatalTransition :: success (
1068- SessionEvent :: AppliedFeeRange ( psbt_context. clone ( ) ) ,
1069- Receiver {
1070- state : ProvisionalProposal { psbt_context } ,
1071- session_context : self . session_context ,
1072- } ,
1073- )
1047+ Ok ( psbt_context) => MaybeFatalTransition :: success (
1048+ SessionEvent :: AppliedFeeRange ( psbt_context. clone ( ) ) ,
1049+ Receiver {
1050+ state : ProvisionalProposal { psbt_context } ,
1051+ session_context : self . session_context ,
1052+ } ,
1053+ ) ,
1054+ Err ( e) => MaybeFatalTransition :: transient ( ProtocolError :: OriginalPayload ( e. into ( ) ) ) ,
1055+ }
10741056 }
10751057
10761058 pub ( crate ) fn apply_applied_fee_range ( self , psbt_context : PsbtContext ) -> ReceiveSession {
@@ -1103,16 +1085,16 @@ impl Receiver<ProvisionalProposal> {
11031085 ) -> MaybeTransientTransition < SessionEvent , Receiver < PayjoinProposal > , ImplementationError >
11041086 {
11051087 let original_psbt = self . state . psbt_context . original_psbt . clone ( ) ;
1106- let inner = match self . state . psbt_context . finalize_proposal ( wallet_process_psbt) {
1107- Ok ( inner ) => inner ,
1088+ let payjoin_psbt = match self . state . psbt_context . finalize_proposal ( wallet_process_psbt) {
1089+ Ok ( payjoin_psbt ) => payjoin_psbt ,
11081090 Err ( e) => {
11091091 return MaybeTransientTransition :: transient ( e) ;
11101092 }
11111093 } ;
1112- let psbt_context = PsbtContext { payjoin_psbt : inner . clone ( ) , original_psbt } ;
1094+ let psbt_context = PsbtContext { payjoin_psbt : payjoin_psbt . clone ( ) , original_psbt } ;
11131095 let payjoin_proposal = PayjoinProposal { psbt_context : psbt_context. clone ( ) } ;
11141096 MaybeTransientTransition :: success (
1115- SessionEvent :: FinalizedProposal ( inner ) ,
1097+ SessionEvent :: FinalizedProposal ( payjoin_psbt ) ,
11161098 Receiver { state : payjoin_proposal, session_context : self . session_context } ,
11171099 )
11181100 }
@@ -1599,20 +1581,22 @@ pub mod test {
15991581 Ok ( ret)
16001582 }
16011583
1602- let maybe_inputs_seen =
1603- receiver. check_inputs_not_owned ( & mut |_| mock_callback ( & mut call_count, false ) ) ;
1584+ let maybe_inputs_seen = receiver
1585+ . check_inputs_not_owned ( & mut |_| mock_callback ( & mut call_count, false ) )
1586+ . save ( & persister)
1587+ . expect ( "Persister shouldn't fail" ) ;
16041588 assert_eq ! ( call_count, 1 ) ;
16051589
16061590 let outputs_unknown = maybe_inputs_seen
1607- . save ( & persister)
1608- . expect ( "Persister shouldn't fail" )
16091591 . check_no_inputs_seen_before ( & mut |_| mock_callback ( & mut call_count, false ) )
16101592 . save ( & persister)
16111593 . expect ( "Persister shouldn't fail" ) ;
16121594 assert_eq ! ( call_count, 2 ) ;
16131595
16141596 let _wants_outputs = outputs_unknown
1615- . identify_receiver_outputs ( & mut |_| mock_callback ( & mut call_count, true ) ) ;
1597+ . identify_receiver_outputs ( & mut |_| mock_callback ( & mut call_count, true ) )
1598+ . save ( & persister)
1599+ . expect ( "Persister shouldn't fail" ) ;
16161600 // there are 2 receiver outputs so we should expect this callback to run twice incrementing
16171601 // call count twice
16181602 assert_eq ! ( call_count, 4 ) ;
0 commit comments