Skip to content

Commit

Permalink
docs(send): add additional function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBEEFCAF3 committed Nov 26, 2024
1 parent 6e512ff commit f664aa5
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit f664aa5

Please sign in to comment.