Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion payjoin/src/core/uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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

[`bitcoin_uri::Uri`]

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.

/// 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";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// let Example_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pj=https://example.com/pj";
/// let example_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pj=https://example.com/pj";

/// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 PjUri documentation.

/// 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>;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down
Loading