Skip to content

Commit 755d5dc

Browse files
committed
loopd: new loopin state for incorrect amount sweeps
1 parent 6f3c68f commit 755d5dc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

loopd/swapclient_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
306306
case loopdb.StateFailInsufficientConfirmedBalance:
307307
failureReason = clientrpc.FailureReason_FAILURE_REASON_INSUFFICIENT_CONFIRMED_BALANCE
308308

309+
case loopdb.StateFailIncorrectHtlcAmtSwept:
310+
failureReason = clientrpc.FailureReason_FAILURE_REASON_INCORRECT_HTLC_AMT_SWEPT
311+
309312
default:
310313
return nil, fmt.Errorf("unknown swap state: %v", loopSwap.State)
311314
}

loopdb/swapstate.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ const (
7272
// StateFailInsufficientConfirmedBalance indicates that the swap wasn't
7373
// published due to insufficient confirmed balance.
7474
StateFailInsufficientConfirmedBalance SwapState = 12
75+
76+
// StateFailIncorrectHtlcAmtSwept indicates that the amount of an
77+
// externally published loop in htlc that didn't match the swap amount
78+
// has been swept back to the user after the htlc timeout period.
79+
StateFailIncorrectHtlcAmtSwept SwapState = 13
7580
)
7681

7782
// SwapStateType defines the types of swap states that exist. Every swap state
@@ -92,10 +97,7 @@ const (
9297

9398
// Type returns the type of the SwapState it is called on.
9499
func (s SwapState) Type() SwapStateType {
95-
if s == StateInitiated || s == StateHtlcPublished ||
96-
s == StatePreimageRevealed || s == StateFailTemporary ||
97-
s == StateInvoiceSettled {
98-
100+
if s.IsPending() {
99101
return StateTypePending
100102
}
101103

@@ -110,7 +112,7 @@ func (s SwapState) Type() SwapStateType {
110112
func (s SwapState) IsPending() bool {
111113
return s == StateInitiated || s == StateHtlcPublished ||
112114
s == StatePreimageRevealed || s == StateFailTemporary ||
113-
s == StateInvoiceSettled
115+
s == StateInvoiceSettled || s == StateFailIncorrectHtlcAmt
114116
}
115117

116118
// IsFinal returns true if the swap is in a final state.
@@ -160,6 +162,9 @@ func (s SwapState) String() string {
160162
case StateFailInsufficientConfirmedBalance:
161163
return "InsufficientConfirmedBalance"
162164

165+
case StateFailIncorrectHtlcAmtSwept:
166+
return "StateFailIncorrectHtlcAmtSwept"
167+
163168
default:
164169
return "Unknown"
165170
}

0 commit comments

Comments
 (0)