Skip to content

Remove use of payjoin::Url and url::Url in public Api#1057

Merged
DanGould merged 2 commits intopayjoin:masterfrom
benalleng:remove-public-url
Sep 12, 2025
Merged

Remove use of payjoin::Url and url::Url in public Api#1057
DanGould merged 2 commits intopayjoin:masterfrom
benalleng:remove-public-url

Conversation

@benalleng
Copy link
Collaborator

@benalleng benalleng commented Sep 10, 2025

This PR aims to remove the use of Url in the public API args and accepting Url of &Url in our IntoUrl interface.

ChatGpt was used in some error correction along the way and type conversions for strings to urls.

closes #513

Pull Request Checklist

Please confirm the following before requesting review:

@benalleng benalleng self-assigned this Sep 10, 2025
@benalleng benalleng added this to the payjoin-1.0 milestone Sep 10, 2025
@coveralls
Copy link
Collaborator

coveralls commented Sep 10, 2025

Pull Request Test Coverage Report for Build 17654923783

Details

  • 47 of 53 (88.68%) changed or added relevant lines in 10 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 86.011%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/receive/v2/mod.rs 12 13 92.31%
payjoin-cli/src/app/v2/ohttp.rs 2 7 28.57%
Files with Coverage Reduction New Missed Lines %
payjoin/src/core/into_url.rs 1 94.34%
Totals Coverage Status
Change from base Build 17654709120: -0.01%
Covered Lines: 8251
Relevant Lines: 9593

💛 - Coveralls

@benalleng benalleng force-pushed the remove-public-url branch 3 times, most recently from a8892e0 to a4a85f1 Compare September 10, 2025 20:37
Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

Glad to see this started. I have a feeling this overshot the mark by a bit in two main ways

  1. Why is impl IntoUrl removed from the public API for &str when Urls are expected? payjoin::IntoUrl is our way to have a typesafe URL passed without exposing the explicit dependency on url::Url, letting us get rid of the dependency on url in the future. However, we still want a strong Url type contract in the API and IntoUrl gets us there in function definitions.
  2. Why was url::Url removed from payjoin-cli? url::Url in payjoin-cli types still seems appropriate because it minimizes this change for review and allows url::Url to still be removed from the payjoin interface. It lets payjoin-cli continue to have validation on config where it may not otherwise and simply allows the core payjoin crate to go without for the dependency sticklers.

And undershot in one main way: it didn't remove url::Url from the public IntoUrl interface by removing the following lines from into_url.rs as described here

-    impl IntoUrl for &Url {}
-    impl IntoUrl for Url {}

@benalleng
Copy link
Collaborator Author

Thanks for the review, I perhaps misunderstood the exact issue that we really just want to disallow accepting a Url in IntoUrl and other methods instead of trying to transition over to using a string reference instead

As a result it was my intention to try and keep some type arg consistency on the external crates, but I will walk back some of these changes now that I know the scope is a little more narrow.

@benalleng
Copy link
Collaborator Author

benalleng commented Sep 11, 2025

And undershot in one main way: it didn't remove url::Url from the public IntoUrl interface by removing the following lines from into_url.rs as described here

-    impl IntoUrl for &Url {}
-    impl IntoUrl for Url {}

My only question about this is if we remove the Url and &Url from being accepted why not just accept a &str and type convert to a Url internally without using IntoUrl?
I think this is answered here #1057 (comment)

@DanGould
Copy link
Contributor

why not just accept a &str

Also for ergonomics because then you can pass both &str and String. And if we eventually have a payjoin::Url type then we have consistency without contract change, too.

@benalleng benalleng force-pushed the remove-public-url branch 2 times, most recently from 1d66a52 to 3220474 Compare September 11, 2025 17:35
@benalleng benalleng marked this pull request as ready for review September 11, 2025 17:36
Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

Better.

A few things remain:

  1. Why are we expecting valid urls for unparsed inputs. That sounds like a recipe for disaster. I know you know better than that and these instances are just a goofs but c'mon man a panic is srs bizns. This has gotta be fixed.

edit: this was a bit harsh I make booboos like this sometimes too. Hope you don't take it the wrong way, Ben.
2. Lots of to_string where as_str() will do. Indeed we're not auditing the enforcement but I think we can at least use best practice all over the place here to demonstrate minimized mem use.
3. Internal APIs can and should use Url to take advantage of the type's strong validation since we're not pulling that dependency out yet.

let receiver: Arc<corepc_node::Client> = Arc::new(receiver);
let receiver_clone = receiver.clone();
let ohttp_relay = services.ohttp_relay_url();
let ohttp_relay = services.ohttp_relay_url().to_string();
Copy link
Contributor

Choose a reason for hiding this comment

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

as_str

Copy link
Collaborator Author

@benalleng benalleng Sep 11, 2025

Choose a reason for hiding this comment

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

This actually probably should remain a string type with the ownership within the receiver loop

@benalleng benalleng force-pushed the remove-public-url branch 3 times, most recently from 65ab3db to 31b3403 Compare September 11, 2025 19:16
@DanGould DanGould mentioned this pull request Sep 11, 2025
2 tasks
@arminsabouri
Copy link
Collaborator

Heads up @benalleng there is a conflict on this branch after #1046

Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

Needs a slight signature change now that crate::uri is pub and visibility lets us internalize some functions to allow them to take validated url::Url and not have to return Results

@benalleng benalleng force-pushed the remove-public-url branch 3 times, most recently from e4f30aa to f301b1e Compare September 12, 2025 14:48
This commit removes the Url from the public Api where it is an arg in
public api methods and also as an impl in the IntoUrl interface so that
it is not accepted where IntoUrl is used.

This commit does not remove Url internally from the payjoin crate or
remove the use of Url in any external crates, it simply transitions the
type to a `&str` or `String` when passing into payjoin methods.
This is a minor commit in a simplification I found could be made in some
send tests using existing consts
Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

tACK c46687f

Clean 🧽

@DanGould DanGould merged commit 2ad79cd into payjoin:master Sep 12, 2025
10 checks passed
@benalleng benalleng deleted the remove-public-url branch October 6, 2025 18:40
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.

Remove url::Url types from public API

4 participants