Skip to content

Commit

Permalink
Correctly set v=2 query parameter for v2 senders (#320)
Browse files Browse the repository at this point in the history
Fix #311
  • Loading branch information
DanGould authored Jul 11, 2024
2 parents 87f9f06 + fa9cacd commit c3ac51f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion payjoin/src/receive/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl ActiveSession {
/// transaction with extract_tx_to_schedule_broadcast() and schedule, followed by checking
/// that the transaction can be broadcast with check_broadcast_suitability. Otherwise it is safe to
/// call assume_interactive_receive to proceed with validation.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct UncheckedProposal {
inner: super::UncheckedProposal,
context: SessionContext,
Expand Down
5 changes: 4 additions & 1 deletion payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl RequestContext {
self.disable_output_substitution,
self.fee_contribution,
self.min_fee_rate,
"1", // payjoin version
)
.map_err(InternalCreateRequestError::Url)?;
let body = self.psbt.to_string().as_bytes().to_vec();
Expand Down Expand Up @@ -959,6 +960,7 @@ fn serialize_v2_body(
disable_output_substitution,
fee_contribution,
min_feerate,
"2", // payjoin version
)
.map_err(InternalCreateRequestError::Url)?;
let query_params = placeholder_url.query().unwrap_or_default();
Expand All @@ -971,9 +973,10 @@ fn serialize_url(
disable_output_substitution: bool,
fee_contribution: Option<(bitcoin::Amount, usize)>,
min_fee_rate: FeeRate,
version: &str,
) -> Result<Url, url::ParseError> {
let mut url = endpoint;
url.query_pairs_mut().append_pair("v", "1");
url.query_pairs_mut().append_pair("v", version);
if disable_output_substitution {
url.query_pairs_mut().append_pair("disableoutputsubstitution", "1");
}
Expand Down
3 changes: 3 additions & 0 deletions payjoin/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ mod integration {
)
.unwrap();
let proposal = handle_proposal(proposal, receiver);
assert!(!proposal.is_output_substitution_disabled());
let psbt = proposal.psbt();
debug!("Receiver's Payjoin proposal PSBT: {:#?}", &psbt);
psbt.to_string()
Expand Down Expand Up @@ -436,6 +437,7 @@ mod integration {
let proposal =
session.process_res(response.bytes().await?.to_vec().as_slice(), ctx)?.unwrap();
let mut payjoin_proposal = handle_directory_proposal(receiver, proposal);
assert!(!payjoin_proposal.is_output_substitution_disabled());
let (req, ctx) = payjoin_proposal.extract_v2_req()?;
let response = agent.post(req.url).body(req.body).send().await?;
let res = response.bytes().await?.to_vec();
Expand Down Expand Up @@ -546,6 +548,7 @@ mod integration {
};
let proposal = session.process_res(response.as_slice(), ctx).unwrap().unwrap();
let mut payjoin_proposal = handle_directory_proposal(receiver, proposal);
assert!(payjoin_proposal.is_output_substitution_disabled());
// Respond with payjoin psbt within the time window the sender is willing to wait
// this response would be returned as http response to the sender
let (req, ctx) = payjoin_proposal.extract_v2_req().unwrap();
Expand Down

0 comments on commit c3ac51f

Please sign in to comment.