loopout: create LoopOutSwapInfo struct

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

@ -14,7 +14,6 @@ import (
"github.com/lightninglabs/loop/lsat" "github.com/lightninglabs/loop/lsat"
"github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/swap"
"github.com/lightninglabs/loop/sweep" "github.com/lightninglabs/loop/sweep"
"github.com/lightningnetwork/lnd/lntypes"
) )
var ( var (
@ -354,14 +353,14 @@ func (s *Client) resumeSwaps(ctx context.Context,
// //
// The return value is a hash that uniquely identifies the new swap. // The return value is a hash that uniquely identifies the new swap.
func (s *Client) LoopOut(globalCtx context.Context, func (s *Client) LoopOut(globalCtx context.Context,
request *OutRequest) (*lntypes.Hash, btcutil.Address, error) { request *OutRequest) (*LoopOutSwapInfo, error) {
log.Infof("LoopOut %v to %v (channels: %v)", log.Infof("LoopOut %v to %v (channels: %v)",
request.Amount, request.DestAddr, request.OutgoingChanSet, request.Amount, request.DestAddr, request.OutgoingChanSet,
) )
if err := s.waitForInitialized(globalCtx); err != nil { if err := s.waitForInitialized(globalCtx); err != nil {
return nil, nil, err return nil, err
} }
// Create a new swap object for this swap. // Create a new swap object for this swap.
@ -371,7 +370,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
globalCtx, swapCfg, initiationHeight, request, globalCtx, swapCfg, initiationHeight, request,
) )
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
// Post swap to the main loop. // Post swap to the main loop.
@ -379,7 +378,10 @@ func (s *Client) LoopOut(globalCtx context.Context,
// Return hash so that the caller can identify this swap in the updates // Return hash so that the caller can identify this swap in the updates
// stream. // stream.
return &swap.hash, swap.htlc.Address, nil return &LoopOutSwapInfo{
SwapHash: swap.hash,
HtlcAddressP2WSH: swap.htlc.Address,
}, nil
} }
// LoopOutQuote takes a LoopOut amount and returns a break down of estimated // LoopOutQuote takes a LoopOut amount and returns a break down of estimated

@ -45,7 +45,7 @@ func TestSuccess(t *testing.T) {
ctx := createClientTestContext(t, nil) ctx := createClientTestContext(t, nil)
// Initiate loop out. // Initiate loop out.
hash, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest) info, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -59,7 +59,7 @@ func TestSuccess(t *testing.T) {
// Expect client to register for conf. // Expect client to register for conf.
confIntent := ctx.AssertRegisterConf(false) confIntent := ctx.AssertRegisterConf(false)
testSuccess(ctx, testRequest.Amount, *hash, testSuccess(ctx, testRequest.Amount, info.SwapHash,
signalPrepaymentResult, signalSwapPaymentResult, false, signalPrepaymentResult, signalSwapPaymentResult, false,
confIntent, confIntent,
) )
@ -72,7 +72,7 @@ func TestFailOffchain(t *testing.T) {
ctx := createClientTestContext(t, nil) ctx := createClientTestContext(t, nil)
_, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest) _, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -110,7 +110,7 @@ func TestFailWrongAmount(t *testing.T) {
// Modify mock for this subtest. // Modify mock for this subtest.
modifier(ctx.serverMock) modifier(ctx.serverMock)
_, _, err := ctx.swapClient.LoopOut( _, err := ctx.swapClient.LoopOut(
context.Background(), testRequest, context.Background(), testRequest,
) )
if err != expectedErr { if err != expectedErr {

@ -250,6 +250,17 @@ type LoopInSwapInfo struct { // nolint
HtlcAddressNP2WSH btcutil.Address HtlcAddressNP2WSH btcutil.Address
} }
// LoopOutSwapInfo contains essential information of a loop-out swap after the
// swap is initiated.
type LoopOutSwapInfo struct { // nolint:golint
// SwapHash contains the sha256 hash of the swap preimage.
SwapHash lntypes.Hash
// HtlcAddressP2WSH contains the native segwit swap htlc address that
// the server will publish to.
HtlcAddressP2WSH btcutil.Address
}
// SwapInfoKit contains common swap info fields. // SwapInfoKit contains common swap info fields.
type SwapInfoKit struct { type SwapInfoKit struct {
// Hash is the sha256 hash of the preimage that unlocks the htlcs. It // Hash is the sha256 hash of the preimage that unlocks the htlcs. It

@ -103,17 +103,17 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
req.OutgoingChanSet = in.OutgoingChanSet req.OutgoingChanSet = in.OutgoingChanSet
} }
hash, htlc, err := s.impl.LoopOut(ctx, req) info, err := s.impl.LoopOut(ctx, req)
if err != nil { if err != nil {
log.Errorf("LoopOut: %v", err) log.Errorf("LoopOut: %v", err)
return nil, err return nil, err
} }
return &looprpc.SwapResponse{ return &looprpc.SwapResponse{
Id: hash.String(), Id: info.SwapHash.String(),
IdBytes: hash[:], IdBytes: info.SwapHash[:],
HtlcAddress: htlc.String(), HtlcAddress: info.HtlcAddressP2WSH.String(),
HtlcAddressP2Wsh: htlc.String(), HtlcAddressP2Wsh: info.HtlcAddressP2WSH.String(),
}, nil }, nil
} }

Loading…
Cancel
Save