Skip to content

Deduplicate payjoin URI creation logic#812

Closed
Mshehu5 wants to merge 0 commit into
payjoin:masterfrom
Mshehu5:master
Closed

Deduplicate payjoin URI creation logic#812
Mshehu5 wants to merge 0 commit into
payjoin:masterfrom
Mshehu5:master

Conversation

@Mshehu5

@Mshehu5 Mshehu5 commented Jun 26, 2025

Copy link
Copy Markdown
Contributor

This PR introduces a helper function create_pj_uri in the v2 module that centralizes the logic for creating Payjoin URIs from a SessionContext. This eliminates code duplication between SessionHistory::pj_uri and Receiver<WithContext>::pj_uri.

Changes

  • Added a new helper function create_pj_uri in payjoin/src/receive/v2/mod.rs
  • Updated Receiver<WithContext>::pj_uri to use the helper function
  • Updated SessionHistory::pj_uri to use the helper function
  • Removed unused import subdir from session.rs

Benefits

  • Improves maintainability by centralizing URI creation logic
  • Reduces code duplication
  • Preserves the existing API and behavior

Testing

The existing test test_v2_pj_uri passes, confirming that the refactored code behaves identically to the original implementation.

Related Issues

Resolves #804

@coveralls

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 15911058532

Details

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • 37 unchanged lines in 17 files lost coverage.
  • Overall coverage decreased (-0.7%) to 85.504%

Files with Coverage Reduction New Missed Lines %
payjoin-directory/src/lib.rs 1 75.0%
payjoin/src/ohttp.rs 1 70.97%
payjoin/src/receive/mod.rs 1 98.13%
payjoin/src/receive/multiparty/mod.rs 1 89.86%
payjoin/src/receive/v1/mod.rs 1 95.74%
payjoin/src/send/v1.rs 1 94.7%
payjoin/src/send/v2/mod.rs 1 88.13%
payjoin-test-utils/src/lib.rs 1 94.41%
payjoin-cli/src/app/config.rs 2 81.58%
payjoin/src/receive/v2/session.rs 2 93.88%
Totals Coverage Status
Change from base Build 15905219803: -0.7%
Covered Lines: 7261
Relevant Lines: 8492

💛 - Coveralls

Comment thread payjoin/src/receive/v2/mod.rs Outdated
session_context: &SessionContext,
output_substitution: OutputSubstitution,
) -> crate::PjUri<'a> {
use crate::uri::{PayjoinExtras, UrlExt};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is pure bikeshedding, but importing bitcoin_uri::Uri here would be a teensy bit more consistent IMO

@arminsabouri arminsabouri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for picking this up. Approach looks good. I had one comment about the output sub param which can either be addressed in this PR or followed up.
utACK

Comment thread payjoin/src/receive/v2/session.rs Outdated
}
SessionEvent::Created(session_context) => Some(crate::receive::v2::create_pj_uri(
session_context,
OutputSubstitution::Disabled,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for pointing out the mismatch. Output substitution defaults to enabled, unless the Payjoin version is v1. We record the version in the UncheckedProposal session event. So the correct behavior should be: if the session log contains UncheckedProposal, we inspect its version and disable output substitution if it's v1, otherwise leave it enabled. If UncheckedProposal is missing, we default to enabling output substitution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be done in a follow up or included in this PR. I'm inclined to just merge this as is.

Comment thread payjoin/src/receive/v2/mod.rs Outdated
}

/// Creates a Payjoin URI from a session context
pub fn create_pj_uri<'a>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I would remove the verb here and just cal lit pj_uri to be more consistent with the rest of the codebase

@spacebear21

Copy link
Copy Markdown
Collaborator

Whoops, I rebased and force pushed but I guess since the upstream branch was Mshehu5:master this had some weird side effect and closed the PR... @Mshehu5 for next time I recommend making a new branch whenever proposing changes.

I re-opened the PR here with the rebased commit #817

Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from @nothingmuch and @0xBEEFCAF3.
Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from @nothingmuch and @0xBEEFCAF3.
Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from @nothingmuch and @0xBEEFCAF3.
Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from the reviewers
Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from reviewers
Mshehu5 added a commit to Mshehu5/rust-payjoin that referenced this pull request Jun 30, 2025
- Add direct import of `bitcoin_uri::Uri` instead of using relative imports
- Fix output substitution handling to properly default to enabled for v2 and disabled for v1

This addresses the review comments from the reviews
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.

De-dup pj_uri construction in receiver session history

5 participants