diff --git a/client.go b/client.go index fe73cf5..470b701 100644 --- a/client.go +++ b/client.go @@ -14,7 +14,6 @@ import ( "github.com/lightninglabs/loop/lsat" "github.com/lightninglabs/loop/swap" "github.com/lightninglabs/loop/sweep" - "github.com/lightningnetwork/lnd/lntypes" ) var ( @@ -354,14 +353,14 @@ func (s *Client) resumeSwaps(ctx context.Context, // // The return value is a hash that uniquely identifies the new swap. 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)", request.Amount, request.DestAddr, request.OutgoingChanSet, ) if err := s.waitForInitialized(globalCtx); err != nil { - return nil, nil, err + return nil, err } // Create a new swap object for this swap. @@ -371,7 +370,7 @@ func (s *Client) LoopOut(globalCtx context.Context, globalCtx, swapCfg, initiationHeight, request, ) if err != nil { - return nil, nil, err + return nil, err } // 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 // 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 diff --git a/client_test.go b/client_test.go index f4a9382..a2d605d 100644 --- a/client_test.go +++ b/client_test.go @@ -45,7 +45,7 @@ func TestSuccess(t *testing.T) { ctx := createClientTestContext(t, nil) // Initiate loop out. - hash, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest) + info, err := ctx.swapClient.LoopOut(context.Background(), testRequest) if err != nil { t.Fatal(err) } @@ -59,7 +59,7 @@ func TestSuccess(t *testing.T) { // Expect client to register for conf. confIntent := ctx.AssertRegisterConf(false) - testSuccess(ctx, testRequest.Amount, *hash, + testSuccess(ctx, testRequest.Amount, info.SwapHash, signalPrepaymentResult, signalSwapPaymentResult, false, confIntent, ) @@ -72,7 +72,7 @@ func TestFailOffchain(t *testing.T) { ctx := createClientTestContext(t, nil) - _, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest) + _, err := ctx.swapClient.LoopOut(context.Background(), testRequest) if err != nil { t.Fatal(err) } @@ -110,7 +110,7 @@ func TestFailWrongAmount(t *testing.T) { // Modify mock for this subtest. modifier(ctx.serverMock) - _, _, err := ctx.swapClient.LoopOut( + _, err := ctx.swapClient.LoopOut( context.Background(), testRequest, ) if err != expectedErr { diff --git a/interface.go b/interface.go index 287832d..e215402 100644 --- a/interface.go +++ b/interface.go @@ -250,6 +250,17 @@ type LoopInSwapInfo struct { // nolint 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. type SwapInfoKit struct { // Hash is the sha256 hash of the preimage that unlocks the htlcs. It diff --git a/loopd/swapclient_server.go b/loopd/swapclient_server.go index 2973c6f..f01c9dc 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -103,17 +103,17 @@ func (s *swapClientServer) LoopOut(ctx context.Context, req.OutgoingChanSet = in.OutgoingChanSet } - hash, htlc, err := s.impl.LoopOut(ctx, req) + info, err := s.impl.LoopOut(ctx, req) if err != nil { log.Errorf("LoopOut: %v", err) return nil, err } return &looprpc.SwapResponse{ - Id: hash.String(), - IdBytes: hash[:], - HtlcAddress: htlc.String(), - HtlcAddressP2Wsh: htlc.String(), + Id: info.SwapHash.String(), + IdBytes: info.SwapHash[:], + HtlcAddress: info.HtlcAddressP2WSH.String(), + HtlcAddressP2Wsh: info.HtlcAddressP2WSH.String(), }, nil }