Skip to content

Commit a2e766a

Browse files
committed
Document Uri with parse/version/sender example
Add docs clarifying the `bitcoin_uri` and Pjuri. Include an example that parses a Payjoin URI, checks version, and initializes the sender state machine. Docs-only; no code changes.
1 parent b1f09b6 commit a2e766a

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

payjoin/src/core/uri/mod.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,55 @@ impl PayjoinExtras {
105105
pub fn endpoint(&self) -> String { self.pj_param.endpoint() }
106106
pub fn output_substitution(&self) -> OutputSubstitution { self.output_substitution }
107107
}
108-
108+
/// A Bitcoin URI with optional Payjoin support.
109+
///
110+
/// This is a type alias for `bitcoin_uri::Uri` with Payjoin-specific extras. The URI can represent
111+
/// either a standard Bitcoin payment request or one that supports Payjoin transactions.
112+
///
113+
/// # Examples
114+
///
115+
/// ## Parse a URI, check version, and initialize sender
116+
///
117+
/// ```rust
118+
/// use payjoin::{Uri, UriExt};
119+
/// use bitcoin::{psbt::Psbt, FeeRate};
120+
/// use std::str::FromStr;
121+
///
122+
/// let Example_uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01&pj=https://example.com/pj";
123+
/// let pj_uri = Uri::try_from(Example_uri)
124+
/// .expect("parse BIP21")
125+
/// .assume_checked()
126+
/// .check_pj_supported()
127+
/// .expect("URI supports Payjoin");
128+
///
129+
/// // Build a PSBT (placeholder — build this from your wallet)
130+
/// let psbt = Psbt::from_str("cHNidP8BAH0CAAAA...").expect("valid PSBT");
131+
///
132+
/// // Branch by Payjoin version and initialize the appropriate sender
133+
/// match pj_uri.extras.pj_param() {
134+
/// #[cfg(feature = "v1")]
135+
/// payjoin::PjParam::V1(pj_param) => {
136+
/// let _sender = payjoin::send::v1::SenderBuilder::from_parts(
137+
/// psbt, pj_param, &pj_uri.address, pj_uri.amount
138+
/// )
139+
/// .build_recommended(FeeRate::BROADCAST_MIN)
140+
/// .expect("build v1 sender");
141+
/// }
142+
/// payjoin::PjParam::V2(_) => {
143+
/// let _sender = payjoin::send::v2::SenderBuilder::new(psbt, pj_uri)
144+
/// .build_recommended(FeeRate::BROADCAST_MIN)
145+
/// .expect("build v2 sender");
146+
/// }
147+
/// }
109148
pub type Uri<'a, NetworkValidation> = bitcoin_uri::Uri<'a, NetworkValidation, MaybePayjoinExtras>;
149+
150+
/// A Bitcoin URI that is guaranteed to support Payjoin.
151+
///
152+
/// This is a type alias for `bitcoin_uri::Uri` with validated Payjoin support. Unlike [`Uri`],
153+
/// this type guarantees that the URI contains valid Payjoin parameters and can be used for
154+
/// Payjoin operations.
155+
/// See [`Uri`] for a complete example that parses a Bip21 Uri, checks the Payjoin version,
156+
/// and initializes the appropriate sender (V1 or V2).
110157
pub type PjUri<'a> = bitcoin_uri::Uri<'a, NetworkChecked, PayjoinExtras>;
111158

112159
mod sealed {

0 commit comments

Comments
 (0)