Skip to content

Commit c1b048b

Browse files
committed
Document RequestBuilder flow
1 parent 8a3a3bc commit c1b048b

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

payjoin/src/send/mod.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! 1. Parse BIP21 as [`payjoin::Uri`](crate::Uri)
77
//! 2. Construct URI request parameters, a finalized “Original PSBT” paying .amount to .address
88
//! 3. (optional) Spawn a thread or async task that will broadcast the original PSBT fallback after delay (e.g. 1 minute) unless canceled
9-
//! 4. Construct the request [`PjUriExt::create_pj_request()`](crate::PjUriExt::create_pj_request()) with the PSBT and your parameters
9+
//! 4. Construct the request using [`RequestBuilder`](crate::send::RequestBuilder) with the PSBT and payjoin uri
1010
//! 5. Send the request and receive response
1111
//! 6. Process the response with [`Context::process_response()`](crate::send::Context::process_response())
1212
//! 7. Sign and finalize the Payjoin Proposal PSBT
@@ -23,19 +23,16 @@
2323
//! Start by parsing a valid BIP 21 uri having the `pj` parameter. This is the [`bip21`](https://crates.io/crates/bip21) crate under the hood.
2424
//!
2525
//! ```
26-
//! let link = payjoin::Uri::try_from(bip21)
27-
//! .map_err(|e| anyhow!("Failed to create URI from BIP21: {}", e))?;
28-
//!
29-
//! let link = link
30-
//! .check_pj_supported()
31-
//! .map_err(|e| anyhow!("The provided URI doesn't support payjoin (BIP78): {}", e))?;
26+
//! let uri = payjoin::Uri::try_from(bip21)
27+
//! .map_err(|e| anyhow!("Failed to create URI from BIP21: {}", e))?
28+
//! .assume_checked(); // assume bitcoin address is for the right network
3229
//! ```
3330
//!
3431
//! ### 2. Construct URI request parameters, a finalized "Original PSBT" paying `.amount` to `.address`
3532
//!
3633
//! ```
3734
//! let mut outputs = HashMap::with_capacity(1);
38-
//! outputs.insert(link.address.to_string(), amount);
35+
//! outputs.insert(uri.address.to_string(), amount);
3936
//!
4037
//! let options = bitcoincore_rpc::json::WalletCreateFundedPsbtOptions {
4138
//! lock_unspent: Some(true),
@@ -60,10 +57,6 @@
6057
//! let psbt = Psbt::from_str(&psbt) // SHOULD BE PROVIDED BY CRATE AS HELPER USING rust-bitcoin base64 feature
6158
//! .with_context(|| "Failed to load PSBT from base64")?;
6259
//! log::debug!("Original psbt: {:#?}", psbt);
63-
//! let pj_params = payjoin::sender::Configuration::with_fee_contribution(
64-
//! payjoin::bitcoin::Amount::from_sat(10000),
65-
//! None,
66-
//! );
6760
//! ```
6861
//!
6962
//! ### 3. (optional) Spawn a thread or async task that will broadcast the transaction after delay (e.g. 1 minute) unless canceled
@@ -76,8 +69,10 @@
7669
//! ### 4. Construct the request with the PSBT and parameters
7770
//!
7871
//! ```
79-
//! let (req, ctx) = link
80-
//! .create_pj_request(psbt, pj_params)
72+
//! let min_fee_rate = bitcoin::FeeRate::from_sat_per_vb(1); // SPECIFY YOUR USER'S MINIMUM FEE RATE
73+
//! let (req, ctx) = RequestBuilder::from_psbt_and_uri(psbt, uri)
74+
//! .with_context(|| "Failed to create payjoin request")?
75+
//! .build_recommended(min_fee_rate)
8176
//! .with_context(|| "Failed to create payjoin request")?;
8277
//! ```
8378
//!
@@ -89,7 +84,6 @@
8984
//!
9085
//! ```
9186
//! let client = reqwest::blocking::Client::builder()
92-
//! .danger_accept_invalid_certs(danger_accept_invalid_certs)
9387
//! .build()
9488
//! .with_context(|| "Failed to build reqwest http client")?;
9589
//! let response = client
@@ -375,8 +369,8 @@ pub struct Request {
375369

376370
/// Data required for validation of response.
377371
///
378-
/// This type is used to process the response. It is returned from [`PjUriExt::create_pj_request()`](crate::PjUriExt::create_pj_request()) method
379-
/// and you only need to call [`.process_response()`](crate::send::Context::process_response()) on it to continue BIP78 flow.
372+
/// This type is used to process the response. Get it from [`RequestBuilder`](crate::send::RequestBuilder)'s build methods.
373+
/// Then you only need to call [`.process_response()`](crate::send::Context::process_response()) on it to continue BIP78 flow.
380374
pub struct Context {
381375
original_psbt: Psbt,
382376
disable_output_substitution: bool,

0 commit comments

Comments
 (0)