Skip to content

Update Receiver State transition methods to consume self - #1076

Merged
arminsabouri merged 2 commits into
payjoin:masterfrom
arminsabouri:own-self
Sep 16, 2025
Merged

arminsabouri merged 2 commits into
payjoin:masterfrom
arminsabouri:own-self

Conversation

@arminsabouri

Copy link
Copy Markdown
Contributor

Closes: #1050

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls

coveralls commented Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 17749761017

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.006%) to 84.681%

Totals Coverage Status
Change from base Build 17747274549: -0.006%
Covered Lines: 8065
Relevant Lines: 9524

💛 - Coveralls

@arminsabouri arminsabouri self-assigned this Sep 15, 2025
@arminsabouri arminsabouri added this to the payjoin-1.0 milestone Sep 15, 2025

@spacebear21 spacebear21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread payjoin/src/core/persist.rs Outdated
Comment on lines +344 to +350

pub fn stasis(&self) -> Option<&CurrentState> {
match self {
OptionalTransitionOutcome::Stasis(current_state) => Some(current_state),
OptionalTransitionOutcome::Progress(_) => None,
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this addition related to making Receiver<Initialized>::process_response consume self? It seems to just be used in the integration test.

@arminsabouri arminsabouri Sep 15, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@spacebear21 spacebear21 Sep 15, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
                    };

Comment thread payjoin/src/core/receive/v2/mod.rs Resolved
`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.

@spacebear21 spacebear21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d1a4672

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All state transition methods must consume self

4 participants