multi: create init result structs

pull/242/head
Joost Jager 4 years ago
parent 68012f051a
commit 8b215edaa2
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -366,12 +366,13 @@ func (s *Client) LoopOut(globalCtx context.Context,
// Create a new swap object for this swap.
initiationHeight := s.executor.height()
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
swap, err := newLoopOutSwap(
initResult, err := newLoopOutSwap(
globalCtx, swapCfg, initiationHeight, request,
)
if err != nil {
return nil, err
}
swap := initResult.swap
// Post swap to the main loop.
s.executor.initiateSwap(globalCtx, swap)
@ -482,12 +483,13 @@ func (s *Client) LoopIn(globalCtx context.Context,
// Create a new swap object for this swap.
initiationHeight := s.executor.height()
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
swap, err := newLoopInSwap(
initResult, err := newLoopInSwap(
globalCtx, swapCfg, initiationHeight, request,
)
if err != nil {
return nil, err
}
swap := initResult.swap
// Post swap to the main loop.
s.executor.initiateSwap(globalCtx, swap)

@ -63,9 +63,15 @@ type loopInSwap struct {
timeoutAddr btcutil.Address
}
// loopInInitResult contains information about a just-initiated loop in swap.
type loopInInitResult struct {
swap *loopInSwap
}
// newLoopInSwap initiates a new loop in swap.
func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
currentHeight int32, request *LoopInRequest) (*loopInSwap, error) {
currentHeight int32, request *LoopInRequest) (*loopInInitResult,
error) {
// Request current server loop in terms and use these to calculate the
// swap fee that we should subtract from the swap amount in the payment
@ -184,7 +190,9 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
swap.log.Infof("Server message: %v", swapResp.serverMessage)
}
return swap, nil
return &loopInInitResult{
swap: swap,
}, nil
}
// resumeLoopInSwap returns a swap object representing a pending swap that has

@ -35,13 +35,14 @@ func TestLoopInSuccess(t *testing.T) {
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
swap, err := newLoopInSwap(
initResult, err := newLoopInSwap(
context.Background(), cfg,
height, &testLoopInRequest,
)
if err != nil {
t.Fatal(err)
}
swap := initResult.swap
ctx.store.assertLoopInStored()
@ -159,13 +160,14 @@ func testLoopInTimeout(t *testing.T,
req.ExternalHtlc = true
}
s, err := newLoopInSwap(
initResult, err := newLoopInSwap(
context.Background(), cfg,
height, &req,
)
if err != nil {
t.Fatal(err)
}
s := initResult.swap
ctx.store.assertLoopInStored()

@ -73,10 +73,15 @@ type executeConfig struct {
loopOutMaxParts uint32
}
// loopOutInitResult contains information about a just-initiated loop out swap.
type loopOutInitResult struct {
swap *loopOutSwap
}
// newLoopOutSwap initiates a new swap with the server and returns a
// corresponding swap object.
func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
currentHeight int32, request *OutRequest) (*loopOutSwap, error) {
currentHeight int32, request *OutRequest) (*loopOutInitResult, error) {
// Generate random preimage.
var swapPreimage [32]byte
@ -180,7 +185,9 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
swap.log.Infof("Server message: %v", swapResp.serverMessage)
}
return swap, nil
return &loopOutInitResult{
swap: swap,
}, nil
}
// resumeLoopOutSwap returns a swap object representing a pending swap that has

@ -54,12 +54,13 @@ func TestLoopOutPaymentParameters(t *testing.T) {
req := *testRequest
req.OutgoingChanSet = loopdb.ChannelSet{2, 3}
swap, err := newLoopOutSwap(
initResult, err := newLoopOutSwap(
context.Background(), cfg, height, &req,
)
if err != nil {
t.Fatal(err)
}
swap := initResult.swap
// Execute the swap in its own goroutine.
errChan := make(chan error)
@ -150,12 +151,13 @@ func TestLateHtlcPublish(t *testing.T) {
cfg := newSwapConfig(&lnd.LndServices, store, server)
swap, err := newLoopOutSwap(
initResult, err := newLoopOutSwap(
context.Background(), cfg, height, testRequest,
)
if err != nil {
t.Fatal(err)
}
swap := initResult.swap
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
@ -235,12 +237,13 @@ func TestCustomSweepConfTarget(t *testing.T) {
&lnd.LndServices, newStoreMock(t), server,
)
swap, err := newLoopOutSwap(
initResult, err := newLoopOutSwap(
context.Background(), cfg, ctx.Lnd.Height, testRequest,
)
if err != nil {
t.Fatal(err)
}
swap := initResult.swap
// Set up the required dependencies to execute the swap.
//
@ -442,10 +445,11 @@ func TestPreimagePush(t *testing.T) {
&lnd.LndServices, newStoreMock(t), server,
)
swap, err := newLoopOutSwap(
initResult, err := newLoopOutSwap(
context.Background(), cfg, ctx.Lnd.Height, testRequest,
)
require.NoError(t, err)
swap := initResult.swap
// Set up the required dependencies to execute the swap.
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}

Loading…
Cancel
Save