@@ -121,20 +121,57 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
121121func (s * swapClientServer ) marshallSwap (loopSwap * loop.SwapInfo ) (
122122 * looprpc.SwapStatus , error ) {
123123
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.
125134 switch loopSwap .State {
126135 case loopdb .StateInitiated :
127136 state = looprpc .SwapState_INITIATED
137+
128138 case loopdb .StatePreimageRevealed :
129139 state = looprpc .SwapState_PREIMAGE_REVEALED
140+
130141 case loopdb .StateHtlcPublished :
131142 state = looprpc .SwapState_HTLC_PUBLISHED
143+
132144 case loopdb .StateInvoiceSettled :
133145 state = looprpc .SwapState_INVOICE_SETTLED
146+
134147 case loopdb .StateSuccess :
135148 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+
136168 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 {
138175 state = looprpc .SwapState_FAILED
139176 }
140177
@@ -167,6 +204,7 @@ func (s *swapClientServer) marshallSwap(loopSwap *loop.SwapInfo) (
167204 Id : loopSwap .SwapHash .String (),
168205 IdBytes : loopSwap .SwapHash [:],
169206 State : state ,
207+ FailureReason : failureReason ,
170208 InitiationTime : loopSwap .InitiationTime .UnixNano (),
171209 LastUpdateTime : loopSwap .LastUpdate .UnixNano (),
172210 HtlcAddress : htlcAddress ,
0 commit comments