Update Receiver State transition methods to consume self#1076
Update Receiver State transition methods to consume self#1076arminsabouri merged 2 commits intopayjoin:masterfrom
Conversation
Pull Request Test Coverage Report for Build 17749761017Details
💛 - Coveralls |
spacebear21
left a comment
There was a problem hiding this comment.
concept ACK but I was confused by the addition of the statis() method.
I also think the Sender transition methods can be updated to consume self.
payjoin/src/core/persist.rs
Outdated
|
|
||
| pub fn stasis(&self) -> Option<&CurrentState> { | ||
| match self { | ||
| OptionalTransitionOutcome::Stasis(current_state) => Some(current_state), | ||
| OptionalTransitionOutcome::Progress(_) => None, | ||
| } | ||
| } |
There was a problem hiding this comment.
Is this addition related to making Receiver<Initialized>::process_response consume self? It seems to just be used in the integration test.
There was a problem hiding this comment.
yes. Integrations may also need to use this depending on how they are polling.
Pj-cli for example doesnt call this but uses a match
match state_transition {
Ok(OptionalTransitionOutcome::Progress(next_state)) => {
println!("Got a request from the sender. Responding with a Payjoin proposal.");
return Ok(next_state);
}
Ok(OptionalTransitionOutcome::Stasis(current_state)) => {
session = current_state;
continue;
}
Err(e) => return Err(e.into()),
}In most cases I imagine a match would be cleaner.
Edit: I could update the integration tests to also use a match. I figured it would reduce boilerplate. Lmk
There was a problem hiding this comment.
I see, since the Receiver is consumed callers need a way to get it back. I'm wary of adding helper methods to the public API just to reduce boilerplate unless there's a clear need. I agree matching seems more correct in general so I'd consider deleting all of these helper methods on OptionalTransitionOutcome or making them pub(crate).
There was a problem hiding this comment.
Replaced with a if let clause
let mut session =
if let OptionalTransitionOutcome::Stasis(current_state) = response_body {
current_state
} else {
panic!("Should still be in initialized state")
};`Receiver<Initialized>::process_response` does not mutate the session context and should consume self.
Callers should give up ownership of the proposal after calling the typestate transition method.
6533867 to
d1a4672
Compare
Closes: #1050
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.