From 4e6a53972916a752be960a72cfc54e2e7b98a239 Mon Sep 17 00:00:00 2001 From: Ikeh Celestine Chukwudi Date: Wed, 2 Dec 2026 12:53:55 +0100 Subject: [PATCH] fix(payjoin): print progress messages to stderr receive_payjoin, send_payjoin and resume_payjoin printed progress messages to stdout alongside their JSON output, so the output could not be parsed as JSON. Print them to stderr instead, so they still show in the terminal and stdout carries only the JSON. Fixes #397 --- CHANGELOG.md | 1 + src/handlers/payjoin/mod.rs | 40 ++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85926de9..6af22d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details. - Gated `full_scan`'s `--scan-stop-gap` to the Electrum and Esplora backends that use it; RPC and CBF wallets now reject the flag instead of silently ignoring it, while a `STOP_GAP` environment variable keeps working for supported backends and no longer breaks unsupported ones - Changed `payjoin history` to return JSON instead of a rendered table - Fixed `wallet config --force` silently changing an existing wallet's network, which left the wallet unable to load; it is now rejected +- Fixed `receive_payjoin`, `send_payjoin` and `resume_payjoin` printing progress messages to stdout, which broke their JSON output; progress is now printed to stderr ## [4.0.0] diff --git a/src/handlers/payjoin/mod.rs b/src/handlers/payjoin/mod.rs index 43516214..50b02632 100644 --- a/src/handlers/payjoin/mod.rs +++ b/src/handlers/payjoin/mod.rs @@ -161,8 +161,8 @@ impl<'a> PayjoinManager<'a> { })?; let pj_uri = receiver.pj_uri(); - println!("Request Payjoin by sharing this Payjoin Uri:"); - println!("{pj_uri}"); + eprintln!("Request Payjoin by sharing this Payjoin Uri:"); + eprintln!("{pj_uri}"); self.proceed_receiver_session( ReceiveSession::Initialized(receiver.clone()), @@ -259,7 +259,7 @@ impl<'a> PayjoinManager<'a> { replay_sender_event_log(&sender_persister).map_err(|e| { Error::Generic(format!("Failed to replay sender event log: {e:?}")) })?; - println!("Resuming existing sender session"); + eprintln!("Resuming existing sender session"); (send_session, sender_persister) } else { let persister = { @@ -369,7 +369,7 @@ impl<'a> PayjoinManager<'a> { .save(persister); match state_transition { Ok(OptionalTransitionOutcome::Progress(next_state)) => { - println!("Got a request from the sender. Responding with a Payjoin proposal."); + eprintln!("Got a request from the sender. Responding with a Payjoin proposal."); break next_state; } Ok(OptionalTransitionOutcome::Stasis(current_state)) => { @@ -408,10 +408,10 @@ impl<'a> PayjoinManager<'a> { )) })?; - println!( + eprintln!( "Checking whether the original proposal can be broadcasted itself is not supported. If the Payjoin fails, manually fall back to the transaction below." ); - println!( + eprintln!( "{}", serialize_hex(&next_receiver_typestate.extract_tx_to_schedule_broadcast()) ); @@ -611,7 +611,7 @@ impl<'a> PayjoinManager<'a> { let next_receiver_typestate = receiver .process_response(&res.bytes().await?, ctx) .save(persister)?; - println!( + eprintln!( "Response successful. TXID: {}", payjoin_psbt.extract_tx_unchecked_fee_rate().compute_txid() ); @@ -636,7 +636,7 @@ impl<'a> PayjoinManager<'a> { let sync_interval = tokio::time::Duration::from_secs(3); let timeout_duration = tokio::time::Duration::from_secs(15); - println!( + eprintln!( "Polling for Payjoin transaction broadcast. This may take up to {} seconds...", timeout_duration.as_secs() ); @@ -669,7 +669,7 @@ impl<'a> PayjoinManager<'a> { .save(persister); if let Ok(OptionalTransitionOutcome::Progress(_)) = check_result { - println!("Payjoin transaction detected in the mempool!"); + eprintln!("Payjoin transaction detected in the mempool!"); return Ok(()); } // For Stasis or Err, continue polling (implicit - falls through to next loop iteration) @@ -778,11 +778,11 @@ impl<'a> PayjoinManager<'a> { .save(persister); match processed_response { Ok(OptionalTransitionOutcome::Progress(psbt)) => { - println!("Proposal received. Processing..."); + eprintln!("Proposal received. Processing..."); return self.process_payjoin_proposal(psbt, blockchain_client).await; } Ok(OptionalTransitionOutcome::Stasis(current_state)) => { - println!("No response yet. Continuing polling..."); + eprintln!("No response yet. Continuing polling..."); sender = current_state; continue; } @@ -889,14 +889,14 @@ impl<'a> PayjoinManager<'a> { let mut timed_out = 0usize; let mut failed = 0usize; - println!("Resuming {} payjoin session(s)...\n", total_sessions); + eprintln!("Resuming {} payjoin session(s)...\n", total_sessions); // Resume receiver sessions for session_id in recv_session_ids { let persister = ReceiverPersister::from_id(db.clone(), session_id.clone()); match replay_receiver_event_log(&persister) { Ok((receiver_state, _)) => { - println!("Resuming receiver session {}", session_id); + eprintln!("Resuming receiver session {}", session_id); match tokio::time::timeout( std::time::Duration::from_secs(30), self.proceed_receiver_session( @@ -913,17 +913,17 @@ impl<'a> PayjoinManager<'a> { } Ok(Err(e)) => { failed += 1; - println!("Receiver session {} failed: {}", session_id, e); + eprintln!("Receiver session {} failed: {}", session_id, e); } Err(_) => { timed_out += 1; - println!("Receiver session {} timed out", session_id); + eprintln!("Receiver session {} timed out", session_id); } } } Err(e) => { failed += 1; - println!("Failed to replay receiver session {}: {:?}", session_id, e); + eprintln!("Failed to replay receiver session {}: {:?}", session_id, e); } } } @@ -933,7 +933,7 @@ impl<'a> PayjoinManager<'a> { let persister = SenderPersister::from_id(db.clone(), session_id.clone()); match replay_sender_event_log(&persister) { Ok((sender_state, _)) => { - println!("Resuming sender session {}", session_id); + eprintln!("Resuming sender session {}", session_id); match tokio::time::timeout( std::time::Duration::from_secs(30), self.proceed_sender_session(sender_state, &persister, blockchain_client), @@ -945,17 +945,17 @@ impl<'a> PayjoinManager<'a> { } Ok(Err(e)) => { failed += 1; - println!("Sender session {} failed: {}", session_id, e); + eprintln!("Sender session {} failed: {}", session_id, e); } Err(_) => { timed_out += 1; - println!("Sender session {} timed out", session_id); + eprintln!("Sender session {} timed out", session_id); } } } Err(e) => { failed += 1; - println!("Failed to replay sender session {}: {:?}", session_id, e); + eprintln!("Failed to replay sender session {}: {:?}", session_id, e); } } }