Deduplicate payjoin URI creation logic#812
Conversation
Pull Request Test Coverage Report for Build 15911058532Details
💛 - Coveralls |
| session_context: &SessionContext, | ||
| output_substitution: OutputSubstitution, | ||
| ) -> crate::PjUri<'a> { | ||
| use crate::uri::{PayjoinExtras, UrlExt}; |
There was a problem hiding this comment.
this is pure bikeshedding, but importing bitcoin_uri::Uri here would be a teensy bit more consistent IMO
arminsabouri
left a comment
There was a problem hiding this comment.
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
| } | ||
| SessionEvent::Created(session_context) => Some(crate::receive::v2::create_pj_uri( | ||
| session_context, | ||
| OutputSubstitution::Disabled, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This can be done in a follow up or included in this PR. I'm inclined to just merge this as is.
| } | ||
|
|
||
| /// Creates a Payjoin URI from a session context | ||
| pub fn create_pj_uri<'a>( |
There was a problem hiding this comment.
Nit: I would remove the verb here and just cal lit pj_uri to be more consistent with the rest of the codebase
- 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.
- 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.
- 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.
- 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
- 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
- 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
This PR introduces a helper function
create_pj_uriin the v2 module that centralizes the logic for creating Payjoin URIs from aSessionContext. This eliminates code duplication betweenSessionHistory::pj_uriandReceiver<WithContext>::pj_uri.Changes
create_pj_uriinpayjoin/src/receive/v2/mod.rsReceiver<WithContext>::pj_urito use the helper functionSessionHistory::pj_urito use the helper functionsubdirfromsession.rsBenefits
Testing
The existing test
test_v2_pj_uripasses, confirming that the refactored code behaves identically to the original implementation.Related Issues
Resolves #804