Skip to content

Commit

Permalink
Fix #154 process_response return ResponseError
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Dec 29, 2023
1 parent 26f0d06 commit 13d50f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions payjoin-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl App {

#[cfg(feature = "v2")]
async fn long_poll_post(&self, req_ctx: &payjoin::send::RequestContext) -> Result<Psbt> {
use payjoin::send::ResponseError;
loop {
let (req, ctx) = req_ctx.extract_v2(&self.config.ohttp_proxy)?;
println!("Sending fallback request to {}", &req.url);
Expand All @@ -208,12 +209,13 @@ impl App {
.await??;

println!("Sent fallback transaction");
let psbt = ctx.process_response(&mut response.into_reader())?;
if let Some(psbt) = psbt {
return Ok(psbt);
} else {
log::info!("No response yet for POST payjoin request, retrying some seconds");
std::thread::sleep(std::time::Duration::from_secs(5));
match ctx.process_response(&mut response.into_reader()) {
Ok(Some(psbt)) => return Ok(psbt),
Ok(None) => std::thread::sleep(std::time::Duration::from_secs(5)),
Err(re) => {
println!("{}", re);
log::debug!("{:?}", re);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion payjoin/src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl ContextV2 {
pub fn process_response(
self,
response: &mut impl std::io::Read,
) -> Result<Option<Psbt>, ValidationError> {
) -> Result<Option<Psbt>, ResponseError> {
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(self.ohttp_res, &res_buf)
Expand Down

0 comments on commit 13d50f1

Please sign in to comment.