|
6 | 6 | //! 1. Parse BIP21 as [`payjoin::Uri`](crate::Uri) |
7 | 7 | //! 2. Construct URI request parameters, a finalized “Original PSBT” paying .amount to .address |
8 | 8 | //! 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 |
10 | 10 | //! 5. Send the request and receive response |
11 | 11 | //! 6. Process the response with [`Context::process_response()`](crate::send::Context::process_response()) |
12 | 12 | //! 7. Sign and finalize the Payjoin Proposal PSBT |
|
23 | 23 | //! 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. |
24 | 24 | //! |
25 | 25 | //! ``` |
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 |
32 | 29 | //! ``` |
33 | 30 | //! |
34 | 31 | //! ### 2. Construct URI request parameters, a finalized "Original PSBT" paying `.amount` to `.address` |
35 | 32 | //! |
36 | 33 | //! ``` |
37 | 34 | //! let mut outputs = HashMap::with_capacity(1); |
38 | | -//! outputs.insert(link.address.to_string(), amount); |
| 35 | +//! outputs.insert(uri.address.to_string(), amount); |
39 | 36 | //! |
40 | 37 | //! let options = bitcoincore_rpc::json::WalletCreateFundedPsbtOptions { |
41 | 38 | //! lock_unspent: Some(true), |
|
60 | 57 | //! let psbt = Psbt::from_str(&psbt) // SHOULD BE PROVIDED BY CRATE AS HELPER USING rust-bitcoin base64 feature |
61 | 58 | //! .with_context(|| "Failed to load PSBT from base64")?; |
62 | 59 | //! 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 | | -//! ); |
67 | 60 | //! ``` |
68 | 61 | //! |
69 | 62 | //! ### 3. (optional) Spawn a thread or async task that will broadcast the transaction after delay (e.g. 1 minute) unless canceled |
|
76 | 69 | //! ### 4. Construct the request with the PSBT and parameters |
77 | 70 | //! |
78 | 71 | //! ``` |
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) |
81 | 76 | //! .with_context(|| "Failed to create payjoin request")?; |
82 | 77 | //! ``` |
83 | 78 | //! |
|
89 | 84 | //! |
90 | 85 | //! ``` |
91 | 86 | //! let client = reqwest::blocking::Client::builder() |
92 | | -//! .danger_accept_invalid_certs(danger_accept_invalid_certs) |
93 | 87 | //! .build() |
94 | 88 | //! .with_context(|| "Failed to build reqwest http client")?; |
95 | 89 | //! let response = client |
@@ -375,8 +369,8 @@ pub struct Request { |
375 | 369 |
|
376 | 370 | /// Data required for validation of response. |
377 | 371 | /// |
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. |
380 | 374 | pub struct Context { |
381 | 375 | original_psbt: Psbt, |
382 | 376 | disable_output_substitution: bool, |
|
0 commit comments