Skip to content
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
10 changes: 8 additions & 2 deletions lianad/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum CommandError {
FailedToFetchOhttpKeys(FetchOhttpKeysError),
// Same FIXME as `SpendFinalization`
FailedToPostOriginalPayjoinProposal(String),
ReplayError(String),
}

impl fmt::Display for CommandError {
Expand Down Expand Up @@ -152,6 +153,9 @@ impl fmt::Display for CommandError {
Self::FailedToPostOriginalPayjoinProposal(e) => {
write!(f, "Failed to post original payjoin proposal: '{}'.", e)
}
Self::ReplayError(e) => {
write!(f, "Payjoin replay failed: '{}'.", e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
write!(f, "Payjoin replay failed: '{}'.", e)
write!(f, "Payjoin session replay failed: '{}'.", e)

}
}
}
}
Expand Down Expand Up @@ -469,14 +473,16 @@ impl DaemonControl {
if let Some(session_id) = db_conn.get_payjoin_receiver_session_id_from_txid(txid) {
let persister =
ReceiverPersister::from_id(Arc::new(self.db.clone()), session_id.clone());
let (state, _) = replay_receiver_event_log(&persister).unwrap();
let (state, _) = replay_receiver_event_log(&persister)
.map_err(|e| CommandError::ReplayError(format!("Receiver replay failed: {e:?}")))?;
return Ok(state.into());
}

if let Some(session_id) = db_conn.get_payjoin_sender_session_id_from_txid(txid) {
log::info!("Checking sender session: {:?}", session_id);
let persister = SenderPersister::from_id(Arc::new(self.db.clone()), session_id.clone());
let (state, _) = replay_sender_event_log(&persister).unwrap();
let (state, _) = replay_sender_event_log(&persister)
.map_err(|e| CommandError::ReplayError(format!("Sender replay failed: {e:?}")))?;
log::info!("Sender state: {:?}", state);
return Ok(state.into());
}
Expand Down
4 changes: 4 additions & 0 deletions lianad/src/jsonrpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Request {

/// A failure to broadcast a transaction to the P2P network.
const BROADCAST_ERROR: i64 = 1_000;
const REPLAY_ERROR: i64 = 1_001;

/// JSONRPC2 error codes. See https://www.jsonrpc.org/specification#error_object.
#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -177,6 +178,9 @@ impl From<commands::CommandError> for Error {
commands::CommandError::FailedToPostOriginalPayjoinProposal(_) => {
Error::new(ErrorCode::ServerError(BROADCAST_ERROR), e.to_string())
}
commands::CommandError::ReplayError(_) => {
Error::new(ErrorCode::ServerError(REPLAY_ERROR), e.to_string())
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lianad/src/payjoin/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn read_from_directory(
let mut receiver = receiver;
let (req, context) = receiver
.create_poll_request(OHTTP_RELAY)
.expect("Failed to extract request");
.map_err(|e| format!("Failed to extract request: {:?}", e))?;

let proposal = match post_request(req.clone()) {
Ok(ohttp_response) => {
let response_bytes = ohttp_response.bytes()?;
Expand Down
Loading