@@ -52,6 +52,10 @@ type loopOutSwap struct {
5252
5353 loopdb.LoopOutContract
5454
55+ executeConfig
56+
57+ htlc * swap.Htlc
58+
5559 swapPaymentChan chan lndclient.PaymentResult
5660 prePaymentChan chan lndclient.PaymentResult
5761}
@@ -134,19 +138,25 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
134138 },
135139 }
136140
137- swapKit , err := newSwapKit (
141+ swapKit := newSwapKit (
138142 swapHash , swap .TypeOut , cfg , & contract .SwapContract ,
139- swap .HtlcP2WSH ,
140143 )
144+
145+ swapKit .lastUpdateTime = initiationTime
146+
147+ // Create the htlc.
148+ htlc , err := swapKit .getHtlc (swap .HtlcP2WSH )
141149 if err != nil {
142150 return nil , err
143151 }
144152
145- swapKit .lastUpdateTime = initiationTime
153+ // Log htlc address for debugging.
154+ swapKit .log .Infof ("Htlc address: %v" , htlc .Address )
146155
147156 swap := & loopOutSwap {
148157 LoopOutContract : contract ,
149158 swapKit : * swapKit ,
159+ htlc : htlc ,
150160 }
151161
152162 // Persist the data before exiting this function, so that the caller
@@ -168,17 +178,24 @@ func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig,
168178
169179 log .Infof ("Resuming loop out swap %v" , hash )
170180
171- swapKit , err := newSwapKit (
181+ swapKit := newSwapKit (
172182 hash , swap .TypeOut , cfg , & pend .Contract .SwapContract ,
173- swap .HtlcP2WSH ,
174183 )
184+
185+ // Create the htlc.
186+ htlc , err := swapKit .getHtlc (swap .HtlcP2WSH )
175187 if err != nil {
176188 return nil , err
177189 }
178190
191+ // Log htlc address for debugging.
192+ swapKit .log .Infof ("Htlc address: %v" , htlc .Address )
193+
194+ // Create the swap.
179195 swap := & loopOutSwap {
180196 LoopOutContract : * pend .Contract ,
181197 swapKit : * swapKit ,
198+ htlc : htlc ,
182199 }
183200
184201 lastUpdate := pend .LastUpdate ()
@@ -192,6 +209,22 @@ func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig,
192209 return swap , nil
193210}
194211
212+ // sendUpdate reports an update to the swap state.
213+ func (s * loopOutSwap ) sendUpdate (ctx context.Context ) error {
214+ info := s .swapInfo ()
215+ s .log .Infof ("Loop out swap state: %v" , info .State )
216+
217+ info .HtlcAddress = s .htlc .Address
218+
219+ select {
220+ case s .statusChan <- * info :
221+ case <- ctx .Done ():
222+ return ctx .Err ()
223+ }
224+
225+ return nil
226+ }
227+
195228// execute starts/resumes the swap. It is a thin wrapper around
196229// executeAndFinalize to conveniently handle the error case.
197230func (s * loopOutSwap ) execute (mainCtx context.Context ,
0 commit comments