@@ -161,27 +161,29 @@ impl<State> core::ops::DerefMut for Sender<State> {
161161 fn deref_mut ( & mut self ) -> & mut Self :: Target { & mut self . state }
162162}
163163
164+ /// Represents the various states of a Payjoin send session during the protocol flow.
165+ ///
166+ /// This provides type erasure for the send session state, allowing the session to be replayed
167+ /// and the state to be updated with the next event over a uniform interface.
164168#[ derive( Debug , Clone , PartialEq , Eq ) ]
165- pub enum SenderTypeState {
169+ pub enum SendSession {
166170 Uninitialized ,
167171 WithReplyKey ( Sender < WithReplyKey > ) ,
168172 V2GetContext ( Sender < V2GetContext > ) ,
169173 ProposalReceived ( Psbt ) ,
170174 TerminalFailure ,
171175}
172176
173- impl SenderTypeState {
174- fn process_event ( self , event : SessionEvent ) -> Result < SenderTypeState , ReplayError > {
177+ impl SendSession {
178+ fn process_event ( self , event : SessionEvent ) -> Result < SendSession , ReplayError > {
175179 match ( self , event) {
176- (
177- SenderTypeState :: Uninitialized ,
178- SessionEvent :: CreatedReplyKey ( sender_with_reply_key) ,
179- ) => Ok ( SenderTypeState :: WithReplyKey ( Sender { state : sender_with_reply_key } ) ) ,
180- ( SenderTypeState :: WithReplyKey ( state) , SessionEvent :: V2GetContext ( v2_get_context) ) =>
180+ ( SendSession :: Uninitialized , SessionEvent :: CreatedReplyKey ( sender_with_reply_key) ) =>
181+ Ok ( SendSession :: WithReplyKey ( Sender { state : sender_with_reply_key } ) ) ,
182+ ( SendSession :: WithReplyKey ( state) , SessionEvent :: V2GetContext ( v2_get_context) ) =>
181183 Ok ( state. apply_v2_get_context ( v2_get_context) ) ,
182- ( SenderTypeState :: V2GetContext ( _state) , SessionEvent :: ProposalReceived ( proposal) ) =>
183- Ok ( SenderTypeState :: ProposalReceived ( proposal) ) ,
184- ( _, SessionEvent :: SessionInvalid ( _) ) => Ok ( SenderTypeState :: TerminalFailure ) ,
184+ ( SendSession :: V2GetContext ( _state) , SessionEvent :: ProposalReceived ( proposal) ) =>
185+ Ok ( SendSession :: ProposalReceived ( proposal) ) ,
186+ ( _, SessionEvent :: SessionInvalid ( _) ) => Ok ( SendSession :: TerminalFailure ) ,
185187 ( current_state, event) => Err ( InternalReplayError :: InvalidStateAndEvent (
186188 Box :: new ( current_state) ,
187189 Box :: new ( event) ,
@@ -303,8 +305,8 @@ impl Sender<WithReplyKey> {
303305 /// The endpoint in the Payjoin URI
304306 pub fn endpoint ( & self ) -> & Url { self . v1 . endpoint ( ) }
305307
306- pub ( crate ) fn apply_v2_get_context ( self , v2_get_context : V2GetContext ) -> SenderTypeState {
307- SenderTypeState :: V2GetContext ( Sender { state : v2_get_context } )
308+ pub ( crate ) fn apply_v2_get_context ( self , v2_get_context : V2GetContext ) -> SendSession {
309+ SendSession :: V2GetContext ( Sender { state : v2_get_context } )
308310 }
309311}
310312
0 commit comments