Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify send,receive function documentation #407

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions payjoin/src/receive/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Receiver {
}
}

/// Extratct an OHTTP Encapsulated HTTP GET request for the Original PSBT
/// Extract an OHTTP Encapsulated HTTP GET request for the Original PSBT
pub fn extract_req(&mut self) -> Result<(Request, ohttp::ClientResponse), SessionError> {
if SystemTime::now() > self.context.expiry {
return Err(InternalSessionError::Expired(self.context.expiry).into());
Expand Down Expand Up @@ -237,7 +237,7 @@ impl UncheckedProposal {
///
/// Receiver MUST check that the Original PSBT from the sender
/// can be broadcast, i.e. `testmempoolaccept` bitcoind rpc returns { "allowed": true,.. }
/// for `extract_tx_to_sheculed_broadcast()` before calling this method.
/// for `extract_tx_to_schedule_broadcast()` before calling this method.
///
/// Do this check if you generate bitcoin uri to receive Payjoin on sender request without manual human approval, like a payment processor.
/// Such so called "non-interactive" receivers are otherwise vulnerable to probing attacks.
Expand Down
21 changes: 17 additions & 4 deletions payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ impl<'a> SenderBuilder<'a> {
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "v2", derive(Serialize, Deserialize))]
pub struct Sender {
/// The original PSBT.
psbt: Psbt,
/// The payjoin directory subdirectory to send the request to.
endpoint: Url,
/// Disallow reciever to substitute original outputs.
disable_output_substitution: bool,
/// (maxadditionalfeecontribution, additionalfeeoutputindex)
fee_contribution: Option<(bitcoin::Amount, usize)>,
min_fee_rate: FeeRate,
/// Script of the person being paid
payee: ScriptBuf,
}

Expand Down Expand Up @@ -350,6 +355,7 @@ impl V1Context {

#[cfg(feature = "v2")]
pub struct V2PostContext {
/// The payjoin directory subdirectory to send the request to.
endpoint: Url,
psbt_ctx: PsbtContext,
hpke_ctx: HpkeContext,
Expand Down Expand Up @@ -383,6 +389,7 @@ impl V2PostContext {
#[cfg(feature = "v2")]
#[derive(Debug, Clone)]
pub struct V2GetContext {
/// The payjoin directory subdirectory to send the request to.
endpoint: Url,
psbt_ctx: PsbtContext,
hpke_ctx: HpkeContext,
Expand Down Expand Up @@ -558,7 +565,7 @@ impl PsbtContext {
Ok(())
}

// version and lock time
/// Check that the version and lock time are the same as in the original PSBT.
fn basic_checks(&self, proposal: &Psbt) -> InternalResult<()> {
check_eq!(
proposal.unsigned_tx.version,
Expand Down Expand Up @@ -638,9 +645,9 @@ impl PsbtContext {
Ok(())
}

// Restore Original PSBT utxos that the receiver stripped.
// The BIP78 spec requires utxo information to be removed, but many wallets
// require it to be present to sign.
/// Restore Original PSBT utxos that the receiver stripped.
/// The BIP78 spec requires utxo information to be removed, but many wallets
/// require it to be present to sign.
fn restore_original_utxos(&self, proposal: &mut Psbt) -> InternalResult<()> {
let mut original_inputs = self.original_psbt.input_pairs().peekable();
let proposal_inputs =
Expand Down Expand Up @@ -714,6 +721,8 @@ impl PsbtContext {
}
}

/// Ensure that the payee's output scriptPubKey appears in the list of outputs exactly once,
/// and that the payee's output amount matches the requested amount.
fn check_single_payee(
psbt: &Psbt,
script_pubkey: &Script,
Expand Down Expand Up @@ -763,6 +772,7 @@ fn clear_unneeded_fields(psbt: &mut Psbt) {
}
}

/// Ensure that an additional fee output is sufficient to pay for the specified additional fee
fn check_fee_output_amount(
output: &TxOut,
fee: bitcoin::Amount,
Expand All @@ -779,6 +789,7 @@ fn check_fee_output_amount(
}
}

/// Find the sender's change output index by eliminating the payee's output as a candidate.
fn find_change_index(
psbt: &Psbt,
payee: &Script,
Expand All @@ -805,6 +816,8 @@ fn find_change_index(
Ok(Some((check_fee_output_amount(output, fee, clamp_fee_contribution)?, index)))
}

/// Check that the change output index is not out of bounds
/// and that the additional fee contribution is not less than specified.
fn check_change_index(
psbt: &Psbt,
payee: &Script,
Expand Down