@@ -121,20 +121,57 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
121
121
func (s * swapClientServer ) marshallSwap (loopSwap * loop.SwapInfo ) (
122
122
* looprpc.SwapStatus , error ) {
123
123
124
- var state looprpc.SwapState
124
+ var (
125
+ state looprpc.SwapState
126
+ failureReason = looprpc .FailureReason_FAILURE_REASON_NONE
127
+ )
128
+
129
+ // Set our state var for non-failure states. If we get a failure, we
130
+ // will update our failure reason. To remain backwards compatible with
131
+ // previous versions where we squashed all failure reasons to a single
132
+ // failure state, we set a failure reason for all our different failure
133
+ // states, and set our failed state for all of them.
125
134
switch loopSwap .State {
126
135
case loopdb .StateInitiated :
127
136
state = looprpc .SwapState_INITIATED
137
+
128
138
case loopdb .StatePreimageRevealed :
129
139
state = looprpc .SwapState_PREIMAGE_REVEALED
140
+
130
141
case loopdb .StateHtlcPublished :
131
142
state = looprpc .SwapState_HTLC_PUBLISHED
143
+
132
144
case loopdb .StateInvoiceSettled :
133
145
state = looprpc .SwapState_INVOICE_SETTLED
146
+
134
147
case loopdb .StateSuccess :
135
148
state = looprpc .SwapState_SUCCESS
149
+
150
+ case loopdb .StateFailOffchainPayments :
151
+ failureReason = looprpc .FailureReason_FAILURE_REASON_OFFCHAIN
152
+
153
+ case loopdb .StateFailTimeout :
154
+ failureReason = looprpc .FailureReason_FAILURE_REASON_TIMEOUT
155
+
156
+ case loopdb .StateFailSweepTimeout :
157
+ failureReason = looprpc .FailureReason_FAILURE_REASON_SWEEP_TIMEOUT
158
+
159
+ case loopdb .StateFailInsufficientValue :
160
+ failureReason = looprpc .FailureReason_FAILURE_REASON_INSUFFICIENT_VALUE
161
+
162
+ case loopdb .StateFailTemporary :
163
+ failureReason = looprpc .FailureReason_FAILURE_REASON_TEMPORARY
164
+
165
+ case loopdb .StateFailIncorrectHtlcAmt :
166
+ failureReason = looprpc .FailureReason_FAILURE_REASON_INCORRECT_AMOUNT
167
+
136
168
default :
137
- // Return less granular status over rpc.
169
+ return nil , fmt .Errorf ("unknown swap state: %v" , loopSwap .State )
170
+ }
171
+
172
+ // If we have a failure reason, we have a failure state, so should use
173
+ // our catchall failed state.
174
+ if failureReason != looprpc .FailureReason_FAILURE_REASON_NONE {
138
175
state = looprpc .SwapState_FAILED
139
176
}
140
177
@@ -167,6 +204,7 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
167
204
Id : loopSwap .SwapHash .String (),
168
205
IdBytes : loopSwap .SwapHash [:],
169
206
State : state ,
207
+ FailureReason : failureReason ,
170
208
InitiationTime : loopSwap .InitiationTime .UnixNano (),
171
209
LastUpdateTime : loopSwap .LastUpdate .UnixNano (),
172
210
HtlcAddress : htlcAddress ,
0 commit comments