Skip to content

Commit 2ebbc78

Browse files
committed
swap: add constructor for swap config
1 parent 9571371 commit 2ebbc78

File tree

4 files changed

+22
-41
lines changed

4 files changed

+22
-41
lines changed

client.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,7 @@ func (s *Client) Run(ctx context.Context,
315315
func (s *Client) resumeSwaps(ctx context.Context,
316316
loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) {
317317

318-
swapCfg := &swapConfig{
319-
lnd: s.lndServices,
320-
store: s.Store,
321-
}
318+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
322319

323320
for _, pend := range loopOutSwaps {
324321
if pend.State().State.Type() != loopdb.StateTypePending {
@@ -369,11 +366,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
369366

370367
// Create a new swap object for this swap.
371368
initiationHeight := s.executor.height()
372-
swapCfg := &swapConfig{
373-
lnd: s.lndServices,
374-
store: s.Store,
375-
server: s.Server,
376-
}
369+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
377370
swap, err := newLoopOutSwap(
378371
globalCtx, swapCfg, initiationHeight, request,
379372
)
@@ -486,13 +479,9 @@ func (s *Client) LoopIn(globalCtx context.Context,
486479

487480
// Create a new swap object for this swap.
488481
initiationHeight := s.executor.height()
489-
swapCfg := swapConfig{
490-
lnd: s.lndServices,
491-
store: s.Store,
492-
server: s.Server,
493-
}
482+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
494483
swap, err := newLoopInSwap(
495-
globalCtx, &swapCfg, initiationHeight, request,
484+
globalCtx, swapCfg, initiationHeight, request,
496485
)
497486
if err != nil {
498487
return nil, err

loopin_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ func TestLoopInSuccess(t *testing.T) {
3232

3333
height := int32(600)
3434

35-
cfg := &swapConfig{
36-
lnd: &ctx.lnd.LndServices,
37-
store: ctx.store,
38-
server: ctx.server,
39-
}
35+
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
4036

4137
swap, err := newLoopInSwap(
4238
context.Background(), cfg,
@@ -151,11 +147,7 @@ func testLoopInTimeout(t *testing.T,
151147

152148
height := int32(600)
153149

154-
cfg := &swapConfig{
155-
lnd: &ctx.lnd.LndServices,
156-
store: ctx.store,
157-
server: ctx.server,
158-
}
150+
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
159151

160152
req := testLoopInRequest
161153
if externalValue != 0 {
@@ -282,12 +274,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
282274
defer test.Guard(t)()
283275

284276
ctx := newLoopInTestContext(t)
285-
286-
cfg := &swapConfig{
287-
lnd: &ctx.lnd.LndServices,
288-
store: ctx.store,
289-
server: ctx.server,
290-
}
277+
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
291278

292279
senderKey := [33]byte{4}
293280
receiverKey := [33]byte{5}

loopout_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ func TestLateHtlcPublish(t *testing.T) {
145145

146146
height := int32(600)
147147

148-
cfg := &swapConfig{
149-
lnd: &lnd.LndServices,
150-
store: store,
151-
server: server,
152-
}
148+
cfg := newSwapConfig(&lnd.LndServices, store, server)
153149

154150
swap, err := newLoopOutSwap(
155151
context.Background(), cfg, height, testRequest,
@@ -231,11 +227,10 @@ func TestCustomSweepConfTarget(t *testing.T) {
231227
ctx.Lnd.SetFeeEstimate(testRequest.SweepConfTarget, 250)
232228
ctx.Lnd.SetFeeEstimate(DefaultSweepConfTarget, 10000)
233229

234-
cfg := &swapConfig{
235-
lnd: &lnd.LndServices,
236-
store: newStoreMock(t),
237-
server: newServerMock(),
238-
}
230+
cfg := newSwapConfig(
231+
&lnd.LndServices, newStoreMock(t), newServerMock(),
232+
)
233+
239234
swap, err := newLoopOutSwap(
240235
context.Background(), cfg, ctx.Lnd.Height, testRequest,
241236
)

swap.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ type swapConfig struct {
8282
store loopdb.SwapStore
8383
server swapServerClient
8484
}
85+
86+
func newSwapConfig(lnd *lndclient.LndServices, store loopdb.SwapStore,
87+
server swapServerClient) *swapConfig {
88+
89+
return &swapConfig{
90+
lnd: lnd,
91+
store: store,
92+
server: server,
93+
}
94+
}

0 commit comments

Comments
 (0)