-
Notifications
You must be signed in to change notification settings - Fork 77
Document Uri with parse/version/sender example #1184
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -105,8 +105,55 @@ impl PayjoinExtras { | |||||
| pub fn endpoint(&self) -> String { self.pj_param.endpoint() } | ||||||
| pub fn output_substitution(&self) -> OutputSubstitution { self.output_substitution } | ||||||
| } | ||||||
|
|
||||||
| /// A Bitcoin URI with optional Payjoin support. | ||||||
| /// | ||||||
| /// This is a type alias for `bitcoin_uri::Uri` with Payjoin-specific extras. The URI can represent | ||||||
| /// either a standard Bitcoin payment request or one that supports Payjoin transactions. | ||||||
| /// | ||||||
| /// # Examples | ||||||
| /// | ||||||
| /// ## Parse a URI, check version, and initialize sender | ||||||
| /// | ||||||
| /// ```rust | ||||||
| /// use payjoin::{Uri, UriExt}; | ||||||
| /// use bitcoin::{psbt::Psbt, FeeRate}; | ||||||
| /// use std::str::FromStr; | ||||||
| /// | ||||||
| /// let Example_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pj=https://example.com/pj"; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// let pj_uri = Uri::try_from(Example_uri) | ||||||
| /// .expect("parse BIP21") | ||||||
| /// .assume_checked() | ||||||
| /// .check_pj_supported() | ||||||
| /// .expect("URI supports Payjoin"); | ||||||
| /// | ||||||
| /// // Build a PSBT (placeholder — build this from your wallet) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the section of the sample code after the PJ URI has been initialized should be in the |
||||||
| /// let psbt = Psbt::from_str("cHNidP8BAH0CAAAA...").expect("valid PSBT"); | ||||||
| /// | ||||||
| /// // Branch by Payjoin version and initialize the appropriate sender | ||||||
| /// match pj_uri.extras.pj_param() { | ||||||
| /// #[cfg(feature = "v1")] | ||||||
| /// payjoin::PjParam::V1(pj_param) => { | ||||||
| /// let _sender = payjoin::send::v1::SenderBuilder::from_parts( | ||||||
| /// psbt, pj_param, &pj_uri.address, pj_uri.amount | ||||||
| /// ) | ||||||
| /// .build_recommended(FeeRate::BROADCAST_MIN) | ||||||
| /// .expect("build v1 sender"); | ||||||
| /// } | ||||||
| /// payjoin::PjParam::V2(_) => { | ||||||
| /// let _sender = payjoin::send::v2::SenderBuilder::new(psbt, pj_uri) | ||||||
| /// .build_recommended(FeeRate::BROADCAST_MIN) | ||||||
| /// .expect("build v2 sender"); | ||||||
| /// } | ||||||
| /// } | ||||||
| pub type Uri<'a, NetworkValidation> = bitcoin_uri::Uri<'a, NetworkValidation, MaybePayjoinExtras>; | ||||||
|
|
||||||
| /// A Bitcoin URI that is guaranteed to support Payjoin. | ||||||
| /// | ||||||
| /// This is a type alias for `bitcoin_uri::Uri` with validated Payjoin support. Unlike [`Uri`], | ||||||
| /// this type guarantees that the URI contains valid Payjoin parameters and can be used for | ||||||
| /// Payjoin operations. | ||||||
| /// See [`Uri`] for a complete example that parses a Bip21 Uri, checks the Payjoin version, | ||||||
| /// and initializes the appropriate sender (V1 or V2). | ||||||
| pub type PjUri<'a> = bitcoin_uri::Uri<'a, NetworkChecked, PayjoinExtras>; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in scope, but should we also update the PJ parameters documentation while we're at it to reflect the possible parameters outlined in the BIPs? Would be nice to have them too. |
||||||
|
|
||||||
| mod sealed { | ||||||
|
|
||||||
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.
You can wrap a reference with brackets so that it is like
It's a nice to have as Rust docs will link it with the actual struct, and both the documentation and IDEs will make it easy to move from here to there.