swap: add constructor for swap config

pull/193/head
carla 4 years ago
parent 9571371153
commit 2ebbc78131
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -315,10 +315,7 @@ func (s *Client) Run(ctx context.Context,
func (s *Client) resumeSwaps(ctx context.Context,
loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) {
swapCfg := &swapConfig{
lnd: s.lndServices,
store: s.Store,
}
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
for _, pend := range loopOutSwaps {
if pend.State().State.Type() != loopdb.StateTypePending {
@ -369,11 +366,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
// Create a new swap object for this swap.
initiationHeight := s.executor.height()
swapCfg := &swapConfig{
lnd: s.lndServices,
store: s.Store,
server: s.Server,
}
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
swap, err := newLoopOutSwap(
globalCtx, swapCfg, initiationHeight, request,
)
@ -486,13 +479,9 @@ func (s *Client) LoopIn(globalCtx context.Context,
// Create a new swap object for this swap.
initiationHeight := s.executor.height()
swapCfg := swapConfig{
lnd: s.lndServices,
store: s.Store,
server: s.Server,
}
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
swap, err := newLoopInSwap(
globalCtx, &swapCfg, initiationHeight, request,
globalCtx, swapCfg, initiationHeight, request,
)
if err != nil {
return nil, err

@ -32,11 +32,7 @@ func TestLoopInSuccess(t *testing.T) {
height := int32(600)
cfg := &swapConfig{
lnd: &ctx.lnd.LndServices,
store: ctx.store,
server: ctx.server,
}
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
swap, err := newLoopInSwap(
context.Background(), cfg,
@ -151,11 +147,7 @@ func testLoopInTimeout(t *testing.T,
height := int32(600)
cfg := &swapConfig{
lnd: &ctx.lnd.LndServices,
store: ctx.store,
server: ctx.server,
}
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
req := testLoopInRequest
if externalValue != 0 {
@ -282,12 +274,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
defer test.Guard(t)()
ctx := newLoopInTestContext(t)
cfg := &swapConfig{
lnd: &ctx.lnd.LndServices,
store: ctx.store,
server: ctx.server,
}
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
senderKey := [33]byte{4}
receiverKey := [33]byte{5}

@ -145,11 +145,7 @@ func TestLateHtlcPublish(t *testing.T) {
height := int32(600)
cfg := &swapConfig{
lnd: &lnd.LndServices,
store: store,
server: server,
}
cfg := newSwapConfig(&lnd.LndServices, store, server)
swap, err := newLoopOutSwap(
context.Background(), cfg, height, testRequest,
@ -231,11 +227,10 @@ func TestCustomSweepConfTarget(t *testing.T) {
ctx.Lnd.SetFeeEstimate(testRequest.SweepConfTarget, 250)
ctx.Lnd.SetFeeEstimate(DefaultSweepConfTarget, 10000)
cfg := &swapConfig{
lnd: &lnd.LndServices,
store: newStoreMock(t),
server: newServerMock(),
}
cfg := newSwapConfig(
&lnd.LndServices, newStoreMock(t), newServerMock(),
)
swap, err := newLoopOutSwap(
context.Background(), cfg, ctx.Lnd.Height, testRequest,
)

@ -82,3 +82,13 @@ type swapConfig struct {
store loopdb.SwapStore
server swapServerClient
}
func newSwapConfig(lnd *lndclient.LndServices, store loopdb.SwapStore,
server swapServerClient) *swapConfig {
return &swapConfig{
lnd: lnd,
store: store,
server: server,
}
}

Loading…
Cancel
Save