Skip to content

Commit 0079485

Browse files
committed
Update sender docstrings
Add missing docstrings.
1 parent 2e77b37 commit 0079485

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

payjoin/src/send/v1.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::psbt::PsbtExt;
3232
use crate::request::Request;
3333
pub use crate::PjUri;
3434

35+
/// A builder to construct the properties of a `Sender`.
3536
#[derive(Clone)]
3637
pub struct SenderBuilder<'a> {
3738
pub(crate) psbt: Psbt,
@@ -210,12 +211,14 @@ impl<'a> SenderBuilder<'a> {
210211
}
211212
}
212213

214+
/// A payjoin V1 sender, allowing the construction of a payjoin V1 request
215+
/// and the resulting `V1Context`
213216
#[derive(Clone, PartialEq, Eq, Debug)]
214217
#[cfg_attr(feature = "v2", derive(serde::Serialize, serde::Deserialize))]
215218
pub struct Sender {
216219
/// The original PSBT.
217220
pub(crate) psbt: Psbt,
218-
/// The payjoin directory subdirectory to send the request to.
221+
/// The endpoint in the Payjoin URI
219222
pub(crate) endpoint: Url,
220223
/// Whether the receiver is allowed to substitute original outputs.
221224
pub(crate) output_substitution: OutputSubstitution,
@@ -251,13 +254,14 @@ impl Sender {
251254
)
252255
}
253256

257+
/// The endpoint in the Payjoin URI
254258
pub fn endpoint(&self) -> &Url { &self.endpoint }
255259
}
256260

257261
/// Data required to validate the response.
258262
///
259263
/// This type is used to process a BIP78 response.
260-
/// Then call [`Self::process_response`] on it to continue BIP78 flow.
264+
/// Call [`Self::process_response`] on it to continue the BIP78 flow.
261265
#[derive(Debug, Clone)]
262266
pub struct V1Context {
263267
psbt_context: PsbtContext,

payjoin/src/send/v2/mod.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::{HpkeKeyPair, HpkePublicKey, IntoUrl, OhttpKeys, PjUri, Request};
4141

4242
mod error;
4343

44+
/// A builder to construct the properties of a [`Sender`].
4445
#[derive(Clone)]
4546
pub struct SenderBuilder<'a>(pub(crate) v1::SenderBuilder<'a>);
4647

@@ -123,13 +124,15 @@ impl<'a> SenderBuilder<'a> {
123124
}
124125
}
125126

127+
/// A new payjoin sender, which must be persisted before initiating the payjoin flow.
126128
#[derive(Debug)]
127129
pub struct NewSender {
128130
pub(crate) v1: v1::Sender,
129131
pub(crate) reply_key: HpkeSecretKey,
130132
}
131133

132134
impl NewSender {
135+
/// Saves the new [`Sender`] using the provided persister and returns the storage token.
133136
pub fn persist<P: Persister<Sender>>(
134137
&self,
135138
persister: &mut P,
@@ -139,6 +142,8 @@ impl NewSender {
139142
}
140143
}
141144

145+
/// A payjoin V2 sender, allowing the construction of a payjoin V2 request
146+
/// and the resulting [`V2PostContext`].
142147
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
143148
pub struct Sender {
144149
/// The v1 Sender.
@@ -170,6 +175,7 @@ impl Value for Sender {
170175
}
171176

172177
impl Sender {
178+
/// Loads a [`Sender`] from the provided persister using the storage token.
173179
pub fn load<P: Persister<Sender>>(
174180
token: P::Token,
175181
persister: &P,
@@ -236,6 +242,7 @@ impl Sender {
236242
self.v1.endpoint.receiver_pubkey()
237243
}
238244

245+
/// The endpoint in the Payjoin URI
239246
pub fn endpoint(&self) -> &Url { self.v1.endpoint() }
240247
}
241248

@@ -289,15 +296,29 @@ pub(crate) fn serialize_v2_body(
289296
Ok(format!("{}\n{}", base64, query_params).into_bytes())
290297
}
291298

299+
/// Data required to validate the POST response.
300+
///
301+
/// This type is used to process a BIP77 POST response.
302+
/// Call [`Self::process_response`] on it to continue the BIP77 flow.
292303
pub struct V2PostContext {
293-
/// The payjoin directory subdirectory to send the request to.
304+
/// The endpoint in the Payjoin URI
294305
pub(crate) endpoint: Url,
295306
pub(crate) psbt_ctx: PsbtContext,
296307
pub(crate) hpke_ctx: HpkeContext,
297308
pub(crate) ohttp_ctx: ohttp::ClientResponse,
298309
}
299310

300311
impl V2PostContext {
312+
/// Processes the response for the initial POST message from the sender
313+
/// client in the v2 Payjoin protocol.
314+
///
315+
/// This function decapsulates the response using the provided OHTTP
316+
/// context. If the encapsulated response status is successful, it
317+
/// indicates that the the Original PSBT been accepted. Otherwise, it
318+
/// returns an error with the encapsulated response status code.
319+
///
320+
/// After this function is called, the sender can poll for a Proposal PSBT
321+
/// from the receiver using the returned [`V2GetContext`].
301322
pub fn process_response(self, response: &[u8]) -> Result<V2GetContext, EncapsulationError> {
302323
let response_array: &[u8; crate::directory::ENCAPSULATED_MESSAGE_BYTES] = response
303324
.try_into()
@@ -318,15 +339,20 @@ impl V2PostContext {
318339
}
319340
}
320341

342+
/// Data required to validate the GET response.
343+
///
344+
/// This type is used to make a BIP77 GET request and process the response.
345+
/// Call [`Self::process_response`] on it to continue the BIP77 flow.
321346
#[derive(Debug, Clone)]
322347
pub struct V2GetContext {
323-
/// The payjoin directory subdirectory to send the request to.
348+
/// The endpoint in the Payjoin URI
324349
pub(crate) endpoint: Url,
325350
pub(crate) psbt_ctx: PsbtContext,
326351
pub(crate) hpke_ctx: HpkeContext,
327352
}
328353

329354
impl V2GetContext {
355+
/// Extract an OHTTP Encapsulated HTTP GET request for the Proposal PSBT
330356
pub fn extract_req(
331357
&self,
332358
ohttp_relay: impl IntoUrl,
@@ -354,6 +380,16 @@ impl V2GetContext {
354380
Ok((Request::new_v2(&url, &body), ohttp_ctx))
355381
}
356382

383+
/// Processes the response for the final GET message from the sender client
384+
/// in the v2 Payjoin protocol.
385+
///
386+
/// This function decapsulates the response using the provided OHTTP
387+
/// context. A successful response can either be a Proposal PSBT or an
388+
/// ACCEPTED message indicating no Proposal PSBT is available yet.
389+
/// Otherwise, it returns an error with the encapsulated status code.
390+
///
391+
/// After this function is called, the sender can sign and finalize the
392+
/// PSBT and broadcast the resulting Payjoin transaction to the network.
357393
pub fn process_response(
358394
&self,
359395
response: &[u8],

0 commit comments

Comments
 (0)