Avoid problems when re-ordering / changing Bob's states

Make it explicit in which states we are able NOT to cancel/refund.
This commit is contained in:
Daniel Karzel 2021-03-31 12:21:47 +11:00 committed by Thomas Eizinger
parent e6dd194f77
commit d233e9914e
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
2 changed files with 15 additions and 2 deletions

View File

@ -26,7 +26,14 @@ pub async fn cancel(
BobState::XmrLocked(state4) => state4.cancel(),
BobState::EncSigSent(state4) => state4.cancel(),
BobState::CancelTimelockExpired(state6) => state6,
_ => bail!(
BobState::Started { .. }
| BobState::ExecutionSetupDone(_)
| BobState::BtcRedeemed(_)
| BobState::BtcCancelled(_)
| BobState::BtcRefunded(_)
| BobState::XmrRedeemed { .. }
| BobState::BtcPunished { .. }
| BobState::SafelyAborted => bail!(
"Cannot cancel swap {} because it is in state {} which is not refundable.",
swap_id,
state

View File

@ -24,7 +24,13 @@ pub async fn refund(
BobState::EncSigSent(state4) => state4.cancel(),
BobState::CancelTimelockExpired(state6) => state6,
BobState::BtcCancelled(state6) => state6,
_ => bail!(
BobState::Started { .. }
| BobState::ExecutionSetupDone(_)
| BobState::BtcRedeemed(_)
| BobState::BtcRefunded(_)
| BobState::XmrRedeemed { .. }
| BobState::BtcPunished { .. }
| BobState::SafelyAborted => bail!(
"Cannot refund swap {} because it is in state {} which is not refundable.",
swap_id,
state