Skip to content

Commit

Permalink
Include ohttp ctx in session ctx
Browse files Browse the repository at this point in the history
This was moved in order to persist ContextV2, but RequestContext
is persisted instead.

Reverts c592954
  • Loading branch information
DanGould committed Dec 14, 2023
1 parent b39d7e7 commit 489c18b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions payjoin-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl App {
#[cfg(feature = "v2")]
async fn long_poll_post(&self, req_ctx: &payjoin::send::RequestContext) -> Result<Psbt> {
loop {
let (req, ctx, ohttp) = req_ctx.extract_v2(&self.config.ohttp_proxy)?;
let (req, ctx) = req_ctx.extract_v2(&self.config.ohttp_proxy)?;
println!("Sending fallback request to {}", &req.url);
let http = http_agent()?;
let response = spawn_blocking(move || {
Expand All @@ -209,7 +209,7 @@ impl App {
.await??;

println!("Sent fallback transaction");
let psbt = ctx.process_response(&mut response.into_reader(), ohttp)?;
let psbt = ctx.process_response(&mut response.into_reader())?;
if let Some(psbt) = psbt {
return Ok(psbt);
} else {
Expand Down
8 changes: 4 additions & 4 deletions payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl RequestContext {
pub fn extract_v2(
&self,
ohttp_proxy_url: &str,
) -> Result<(Request, ContextV2, ohttp::ClientResponse), CreateRequestError> {
) -> Result<(Request, ContextV2), CreateRequestError> {
let rs_base64 = crate::v2::subdir(self.endpoint.as_str()).to_string();
log::debug!("rs_base64: {:?}", rs_base64);
let b64_config =
Expand Down Expand Up @@ -471,8 +471,8 @@ impl RequestContext {
min_fee_rate: self.min_fee_rate,
},
e: self.e,
ohttp_res,
},
ohttp_res,
))
}
}
Expand Down Expand Up @@ -654,6 +654,7 @@ pub struct ContextV1 {
pub struct ContextV2 {
context_v1: ContextV1,
e: bitcoin::secp256k1::SecretKey,
ohttp_res: ohttp::ClientResponse,
}

macro_rules! check_eq {
Expand Down Expand Up @@ -686,11 +687,10 @@ impl ContextV2 {
pub fn process_response(
self,
response: &mut impl std::io::Read,
ohttp_ctx: ohttp::ClientResponse,
) -> Result<Option<Psbt>, ValidationError> {
let mut res_buf = Vec::new();
response.read_to_end(&mut res_buf).map_err(InternalValidationError::Io)?;
let mut res_buf = crate::v2::ohttp_decapsulate(ohttp_ctx, &res_buf)
let mut res_buf = crate::v2::ohttp_decapsulate(self.ohttp_res, &res_buf)
.map_err(InternalValidationError::V2)?;
let psbt = crate::v2::decrypt_message_b(&mut res_buf, self.e)
.map_err(InternalValidationError::V2)?;
Expand Down
4 changes: 2 additions & 2 deletions payjoin/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod integration {
// Create a funded PSBT (not broadcasted) to address with amount given in the pj_uri
let psbt = build_original_psbt(&sender, &pj_uri)?;
debug!("Original psbt: {:#?}", psbt);
let (send_req, send_ctx, ohttp) = RequestBuilder::from_psbt_and_uri(psbt, pj_uri)?
let (send_req, send_ctx) = RequestBuilder::from_psbt_and_uri(psbt, pj_uri)?
.build_with_additional_fee(Amount::from_sat(10000), None, FeeRate::ZERO, false)?
.extract_v2(OH_RELAY_URL)?;
log::info!("send fallback v2");
Expand Down Expand Up @@ -298,7 +298,7 @@ mod integration {
})
.await??;
let checked_payjoin_proposal_psbt =
send_ctx.process_response(&mut response.into_reader(), ohttp)?.unwrap();
send_ctx.process_response(&mut response.into_reader())?.unwrap();
let payjoin_tx = extract_pj_tx(&sender, checked_payjoin_proposal_psbt)?;
sender.send_raw_transaction(&payjoin_tx)?;
log::info!("sent");
Expand Down

0 comments on commit 489c18b

Please sign in to comment.