-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change request struct to tuple-struct #87
Conversation
payjoin-cli/src/app.rs
Outdated
.post(req.url) | ||
.body(req.body) | ||
.post(req_url) | ||
.body(req_body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'd initially imagined was a change to more easily deconstruct (req, ctx)
into ((url, body), ctx)
, but I see that one may easily interpret that to instead be deconstructed as in this PR:
let req_url = req.0;
let req_body = req.1;
In hindsight, it actually may make more sense to put context into the request as a named variable so that you have req.url
, req.body
, req.context
and don't have to know about deconstructing the tuple and guess the names. The context is directly related to the particular request anyhow.
I'm going to update the issue to reflect this preference. Thanks for engaging with this so we could come up with a better design.
payjoin/src/send/mod.rs
Outdated
pub struct Request { | ||
/// URL to send the request to. | ||
/// | ||
/// This is full URL with scheme etc - you can pass it right to `reqwest` or a similar library. | ||
pub url: Url, | ||
|
||
/// Bytes to be sent to the receiver. | ||
/// | ||
/// This is properly encoded PSBT, already in base64. You only need to make sure `Content-Type` | ||
/// is `text/plain` and `Content-Length` is `body.len()` (most libraries do the latter | ||
/// automatically). | ||
pub body: Vec<u8>, | ||
} | ||
pub struct Request(pub Url, pub Vec<u8>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another reason to keep the names is to keep the documentation. Adding pub context: context,
to Request
with a docstring should make it easier to handle downstream
14a2484
to
f4dae8c
Compare
@DanGould I moved Question about the inline tests:
"req.ctx" in step 6 would return an error here because req is defined in a different step(4).. does that happen to you as well? |
@jbesraa Thanks for this. I modified the code to make use of borrow instead of making |
It does fail for me as well, and I was wondering why, oops! This documentation would be better suited to a tutorial at https://payjoindevkit.org but I wrote it before that existed! Once that exists, it would make more sense to link to the post from the docstring. In the future if we choose to proceed with Rust Documentation tests, we can use preprocessing and hiding to fix the errors you've come across |
84f0114
to
bb888bb
Compare
Now I see why @Kixunil separated After working through it I think it might actually make sense to leave functionally as-is and document why the separation exists in the create_pj_request function signature. working this through was NOT a waste of time if we end up merging something else @jbesraa, clearly there was a lack of clarity and I think we finally found it. The ergonomic solution may be as simple as /// Prepare an HTTP request and request context to process the response
///
/// An HTTP client will own the Request data while Context sticks around so
/// a `(Request, Context)` tuple is returned to keep them separated. call:
///
/// `let (request, context) = uri.create_pj_request(psbt, params);`
#[cfg(feature = "send")]
fn create_pj_request(
self,
psbt: bitcoin::psbt::Psbt,
params: send::Configuration,
) -> Result<(send::Request, send::Context), send::CreateRequestError>; |
bb888bb
to
d05144b
Compare
d05144b
to
0ff3fb9
Compare
that makes sense @DanGould. pushed the short docs and reverted previous commits |
resolves #80