Skip to content

Commit 0fbf253

Browse files
committed
loopdb: abandon swap state
1 parent 8612912 commit 0fbf253

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

loopdb/swapstate.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const (
6464
// StateFailIncorrectHtlcAmt indicates that the amount of an externally
6565
// published loop in htlc didn't match the swap amount.
6666
StateFailIncorrectHtlcAmt SwapState = 10
67+
68+
// StateFailAbandoned indicates that a swap has been abandoned. Its
69+
// execution has been canceled. It won't further be processed.
70+
StateFailAbandoned SwapState = 11
6771
)
6872

6973
// SwapStateType defines the types of swap states that exist. Every swap state
@@ -98,6 +102,18 @@ func (s SwapState) Type() SwapStateType {
98102
return StateTypeFail
99103
}
100104

105+
// IsPending returns true if the swap is in a pending state.
106+
func (s SwapState) IsPending() bool {
107+
return s == StateInitiated || s == StateHtlcPublished ||
108+
s == StatePreimageRevealed || s == StateFailTemporary ||
109+
s == StateInvoiceSettled
110+
}
111+
112+
// IsFinal returns true if the swap is in a final state.
113+
func (s SwapState) IsFinal() bool {
114+
return !s.IsPending()
115+
}
116+
101117
// String returns a string representation of the swap's state.
102118
func (s SwapState) String() string {
103119
switch s {
@@ -134,6 +150,9 @@ func (s SwapState) String() string {
134150
case StateFailIncorrectHtlcAmt:
135151
return "IncorrectHtlcAmt"
136152

153+
case StateFailAbandoned:
154+
return "FailAbandoned"
155+
137156
default:
138157
return "Unknown"
139158
}

0 commit comments

Comments
 (0)