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

Correctly set v=2 query parameter for v2 senders #320

Merged
merged 1 commit into from
Jul 11, 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
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
Loading