From 0fbf2533912f2a38d492c3153cfd431badf8e40d Mon Sep 17 00:00:00 2001 From: Slyghtning Date: Mon, 13 Nov 2023 14:49:03 +0100 Subject: [PATCH] loopdb: abandon swap state --- loopdb/swapstate.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/loopdb/swapstate.go b/loopdb/swapstate.go index 15d0b74..12c207b 100644 --- a/loopdb/swapstate.go +++ b/loopdb/swapstate.go @@ -64,6 +64,10 @@ const ( // StateFailIncorrectHtlcAmt indicates that the amount of an externally // published loop in htlc didn't match the swap amount. StateFailIncorrectHtlcAmt SwapState = 10 + + // StateFailAbandoned indicates that a swap has been abandoned. Its + // execution has been canceled. It won't further be processed. + StateFailAbandoned SwapState = 11 ) // SwapStateType defines the types of swap states that exist. Every swap state @@ -98,6 +102,18 @@ func (s SwapState) Type() SwapStateType { return StateTypeFail } +// IsPending returns true if the swap is in a pending state. +func (s SwapState) IsPending() bool { + return s == StateInitiated || s == StateHtlcPublished || + s == StatePreimageRevealed || s == StateFailTemporary || + s == StateInvoiceSettled +} + +// IsFinal returns true if the swap is in a final state. +func (s SwapState) IsFinal() bool { + return !s.IsPending() +} + // String returns a string representation of the swap's state. func (s SwapState) String() string { switch s { @@ -134,6 +150,9 @@ func (s SwapState) String() string { case StateFailIncorrectHtlcAmt: return "IncorrectHtlcAmt" + case StateFailAbandoned: + return "FailAbandoned" + default: return "Unknown" }