mirror of
https://github.com/lightninglabs/loop
synced 2024-11-16 00:12:52 +00:00
multi: create init result structs
This commit is contained in:
parent
68012f051a
commit
8b215edaa2
@ -366,12 +366,13 @@ func (s *Client) LoopOut(globalCtx context.Context,
|
|||||||
// Create a new swap object for this swap.
|
// Create a new swap object for this swap.
|
||||||
initiationHeight := s.executor.height()
|
initiationHeight := s.executor.height()
|
||||||
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
|
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
|
||||||
swap, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
globalCtx, swapCfg, initiationHeight, request,
|
globalCtx, swapCfg, initiationHeight, request,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
// Post swap to the main loop.
|
// Post swap to the main loop.
|
||||||
s.executor.initiateSwap(globalCtx, swap)
|
s.executor.initiateSwap(globalCtx, swap)
|
||||||
@ -482,12 +483,13 @@ func (s *Client) LoopIn(globalCtx context.Context,
|
|||||||
// Create a new swap object for this swap.
|
// Create a new swap object for this swap.
|
||||||
initiationHeight := s.executor.height()
|
initiationHeight := s.executor.height()
|
||||||
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
|
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server)
|
||||||
swap, err := newLoopInSwap(
|
initResult, err := newLoopInSwap(
|
||||||
globalCtx, swapCfg, initiationHeight, request,
|
globalCtx, swapCfg, initiationHeight, request,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
// Post swap to the main loop.
|
// Post swap to the main loop.
|
||||||
s.executor.initiateSwap(globalCtx, swap)
|
s.executor.initiateSwap(globalCtx, swap)
|
||||||
|
12
loopin.go
12
loopin.go
@ -63,9 +63,15 @@ type loopInSwap struct {
|
|||||||
timeoutAddr btcutil.Address
|
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.
|
// newLoopInSwap initiates a new loop in swap.
|
||||||
func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
|
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
|
// 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
|
// 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)
|
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
|
// 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)
|
cfg := newSwapConfig(&ctx.lnd.LndServices, ctx.store, ctx.server)
|
||||||
|
|
||||||
swap, err := newLoopInSwap(
|
initResult, err := newLoopInSwap(
|
||||||
context.Background(), cfg,
|
context.Background(), cfg,
|
||||||
height, &testLoopInRequest,
|
height, &testLoopInRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
ctx.store.assertLoopInStored()
|
ctx.store.assertLoopInStored()
|
||||||
|
|
||||||
@ -159,13 +160,14 @@ func testLoopInTimeout(t *testing.T,
|
|||||||
req.ExternalHtlc = true
|
req.ExternalHtlc = true
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := newLoopInSwap(
|
initResult, err := newLoopInSwap(
|
||||||
context.Background(), cfg,
|
context.Background(), cfg,
|
||||||
height, &req,
|
height, &req,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
s := initResult.swap
|
||||||
|
|
||||||
ctx.store.assertLoopInStored()
|
ctx.store.assertLoopInStored()
|
||||||
|
|
||||||
|
11
loopout.go
11
loopout.go
@ -73,10 +73,15 @@ type executeConfig struct {
|
|||||||
loopOutMaxParts uint32
|
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
|
// newLoopOutSwap initiates a new swap with the server and returns a
|
||||||
// corresponding swap object.
|
// corresponding swap object.
|
||||||
func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
|
func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
|
||||||
currentHeight int32, request *OutRequest) (*loopOutSwap, error) {
|
currentHeight int32, request *OutRequest) (*loopOutInitResult, error) {
|
||||||
|
|
||||||
// Generate random preimage.
|
// Generate random preimage.
|
||||||
var swapPreimage [32]byte
|
var swapPreimage [32]byte
|
||||||
@ -180,7 +185,9 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
|
|||||||
swap.log.Infof("Server message: %v", swapResp.serverMessage)
|
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
|
// resumeLoopOutSwap returns a swap object representing a pending swap that has
|
||||||
|
@ -54,12 +54,13 @@ func TestLoopOutPaymentParameters(t *testing.T) {
|
|||||||
req := *testRequest
|
req := *testRequest
|
||||||
req.OutgoingChanSet = loopdb.ChannelSet{2, 3}
|
req.OutgoingChanSet = loopdb.ChannelSet{2, 3}
|
||||||
|
|
||||||
swap, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
context.Background(), cfg, height, &req,
|
context.Background(), cfg, height, &req,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
// Execute the swap in its own goroutine.
|
// Execute the swap in its own goroutine.
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
@ -150,12 +151,13 @@ func TestLateHtlcPublish(t *testing.T) {
|
|||||||
|
|
||||||
cfg := newSwapConfig(&lnd.LndServices, store, server)
|
cfg := newSwapConfig(&lnd.LndServices, store, server)
|
||||||
|
|
||||||
swap, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
context.Background(), cfg, height, testRequest,
|
context.Background(), cfg, height, testRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
|
|
||||||
@ -235,12 +237,13 @@ func TestCustomSweepConfTarget(t *testing.T) {
|
|||||||
&lnd.LndServices, newStoreMock(t), server,
|
&lnd.LndServices, newStoreMock(t), server,
|
||||||
)
|
)
|
||||||
|
|
||||||
swap, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
context.Background(), cfg, ctx.Lnd.Height, testRequest,
|
context.Background(), cfg, ctx.Lnd.Height, testRequest,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
// Set up the required dependencies to execute the swap.
|
// Set up the required dependencies to execute the swap.
|
||||||
//
|
//
|
||||||
@ -442,10 +445,11 @@ func TestPreimagePush(t *testing.T) {
|
|||||||
&lnd.LndServices, newStoreMock(t), server,
|
&lnd.LndServices, newStoreMock(t), server,
|
||||||
)
|
)
|
||||||
|
|
||||||
swap, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
context.Background(), cfg, ctx.Lnd.Height, testRequest,
|
context.Background(), cfg, ctx.Lnd.Height, testRequest,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
swap := initResult.swap
|
||||||
|
|
||||||
// Set up the required dependencies to execute the swap.
|
// Set up the required dependencies to execute the swap.
|
||||||
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
|
||||||
|
Loading…
Reference in New Issue
Block a user