Skip to content

Commit a7e4283

Browse files
authored
Remove ReceivedProposalPsbt infavor of session outcome (payjoin#1171)
2 parents 4b504f4 + 3bdda03 commit a7e4283

4 files changed

Lines changed: 9 additions & 17 deletions

File tree

payjoin-cli/src/app/v2/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ impl StatusText for SendSession {
5252
match self {
5353
SendSession::WithReplyKey(_) | SendSession::PollingForProposal(_) =>
5454
"Waiting for proposal",
55-
SendSession::ProposalReceived(_) => "Proposal received",
5655
SendSession::Closed(session_outcome) => match session_outcome {
5756
SenderSessionOutcome::Failure => "Session failure",
58-
SenderSessionOutcome::Success => "Session success",
57+
SenderSessionOutcome::Success(_) => "Session success",
5958
SenderSessionOutcome::Cancel => "Session cancelled",
6059
},
6160
}
@@ -461,7 +460,7 @@ impl App {
461460
self.post_original_proposal(context, persister).await?,
462461
SendSession::PollingForProposal(context) =>
463462
self.get_proposed_payjoin_psbt(context, persister).await?,
464-
SendSession::ProposalReceived(proposal) => {
463+
SendSession::Closed(SenderSessionOutcome::Success(proposal)) => {
465464
self.process_pj_response(proposal)?;
466465
return Ok(());
467466
}

payjoin-ffi/src/send/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl From<SenderSessionOutcome> for payjoin::send::v2::SessionOutcome {
7272
pub enum SendSession {
7373
WithReplyKey { inner: Arc<WithReplyKey> },
7474
PollingForProposal { inner: Arc<PollingForProposal> },
75-
ProposalReceived { inner: Arc<Psbt> },
7675
Closed { inner: Arc<SenderSessionOutcome> },
7776
}
7877

@@ -84,8 +83,6 @@ impl From<payjoin::send::v2::SendSession> for SendSession {
8483
Self::WithReplyKey { inner: Arc::new(inner.into()) },
8584
SendSession::PollingForProposal(inner) =>
8685
Self::PollingForProposal { inner: Arc::new(inner.into()) },
87-
SendSession::ProposalReceived(inner) =>
88-
Self::ProposalReceived { inner: Arc::new(inner.into()) },
8986
SendSession::Closed(session_outcome) =>
9087
Self::Closed { inner: Arc::new(session_outcome.into()) },
9188
}

payjoin/src/core/send/v2/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ impl<State> Sender<State> {
247247
pub enum SendSession {
248248
WithReplyKey(Sender<WithReplyKey>),
249249
PollingForProposal(Sender<PollingForProposal>),
250-
ProposalReceived(Psbt),
251250
Closed(SessionOutcome),
252251
}
253252

@@ -265,8 +264,8 @@ impl SendSession {
265264
Ok(state.apply_polling_for_proposal()),
266265
(
267266
SendSession::PollingForProposal(_state),
268-
SessionEvent::ReceivedProposalPsbt(proposal),
269-
) => Ok(SendSession::ProposalReceived(proposal)),
267+
SessionEvent::Closed(SessionOutcome::Success(proposal)),
268+
) => Ok(SendSession::Closed(SessionOutcome::Success(proposal))),
270269
(_, SessionEvent::Closed(session_outcome)) => Ok(SendSession::Closed(session_outcome)),
271270
(current_state, event) => Err(InternalReplayError::InvalidEvent(
272271
Box::new(event),
@@ -530,7 +529,7 @@ impl Sender<PollingForProposal> {
530529

531530
MaybeSuccessTransitionWithNoResults::success(
532531
processed_proposal.clone(),
533-
SessionEvent::ReceivedProposalPsbt(processed_proposal),
532+
SessionEvent::Closed(SessionOutcome::Success(processed_proposal)),
534533
)
535534
}
536535
}

payjoin/src/core/send/v2/session.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl SessionHistory {
8585

8686
match self.events.last() {
8787
Some(SessionEvent::Closed(outcome)) => match outcome {
88-
SessionOutcome::Success => SessionStatus::Completed,
88+
SessionOutcome::Success(_) => SessionStatus::Completed,
8989
SessionOutcome::Failure | SessionOutcome::Cancel => SessionStatus::Failed,
9090
},
9191
_ => SessionStatus::Active,
@@ -109,8 +109,6 @@ pub enum SessionEvent {
109109
Created(Box<SessionContext>),
110110
/// Sender POSTed the Original PSBT and is waiting to receive a Proposal PSBT
111111
PostedOriginalPsbt(),
112-
/// Sender received a Proposal PSBT
113-
ReceivedProposalPsbt(bitcoin::Psbt),
114112
/// Closed successful or failed session
115113
Closed(SessionOutcome),
116114
}
@@ -119,7 +117,7 @@ pub enum SessionEvent {
119117
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
120118
pub enum SessionOutcome {
121119
/// Successful payjoin
122-
Success,
120+
Success(bitcoin::Psbt),
123121
/// Payjoin failed to complete due to a counterparty deviation from the protocol
124122
Failure,
125123
/// Payjoin was cancelled by the user
@@ -178,8 +176,7 @@ mod tests {
178176
let test_cases = vec![
179177
SessionEvent::Created(Box::new(sender_with_reply_key.session_context.clone())),
180178
SessionEvent::PostedOriginalPsbt(),
181-
SessionEvent::ReceivedProposalPsbt(PARSED_ORIGINAL_PSBT.clone()),
182-
SessionEvent::Closed(SessionOutcome::Success),
179+
SessionEvent::Closed(SessionOutcome::Success(PARSED_ORIGINAL_PSBT.clone())),
183180
SessionEvent::Closed(SessionOutcome::Failure),
184181
SessionEvent::Closed(SessionOutcome::Cancel),
185182
];
@@ -353,7 +350,7 @@ mod tests {
353350

354351
let events = vec![
355352
SessionEvent::Created(Box::new(with_reply_key.session_context.clone())),
356-
SessionEvent::Closed(SessionOutcome::Success),
353+
SessionEvent::Closed(SessionOutcome::Success(PARSED_ORIGINAL_PSBT.clone())),
357354
];
358355

359356
let session = SessionHistory { events };

0 commit comments

Comments
 (0)