Skip to content

Commit 68012f0

Browse files
committed
loopout: create LoopOutSwapInfo struct
1 parent c6c30e2 commit 68012f0

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

client.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/lightninglabs/loop/lsat"
1515
"github.com/lightninglabs/loop/swap"
1616
"github.com/lightninglabs/loop/sweep"
17-
"github.com/lightningnetwork/lnd/lntypes"
1817
)
1918

2019
var (
@@ -354,14 +353,14 @@ func (s *Client) resumeSwaps(ctx context.Context,
354353
//
355354
// The return value is a hash that uniquely identifies the new swap.
356355
func (s *Client) LoopOut(globalCtx context.Context,
357-
request *OutRequest) (*lntypes.Hash, btcutil.Address, error) {
356+
request *OutRequest) (*LoopOutSwapInfo, error) {
358357

359358
log.Infof("LoopOut %v to %v (channels: %v)",
360359
request.Amount, request.DestAddr, request.OutgoingChanSet,
361360
)
362361

363362
if err := s.waitForInitialized(globalCtx); err != nil {
364-
return nil, nil, err
363+
return nil, err
365364
}
366365

367366
// Create a new swap object for this swap.
@@ -371,15 +370,18 @@ func (s *Client) LoopOut(globalCtx context.Context,
371370
globalCtx, swapCfg, initiationHeight, request,
372371
)
373372
if err != nil {
374-
return nil, nil, err
373+
return nil, err
375374
}
376375

377376
// Post swap to the main loop.
378377
s.executor.initiateSwap(globalCtx, swap)
379378

380379
// Return hash so that the caller can identify this swap in the updates
381380
// stream.
382-
return &swap.hash, swap.htlc.Address, nil
381+
return &LoopOutSwapInfo{
382+
SwapHash: swap.hash,
383+
HtlcAddressP2WSH: swap.htlc.Address,
384+
}, nil
383385
}
384386

385387
// LoopOutQuote takes a LoopOut amount and returns a break down of estimated

client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestSuccess(t *testing.T) {
4545
ctx := createClientTestContext(t, nil)
4646

4747
// Initiate loop out.
48-
hash, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
48+
info, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
4949
if err != nil {
5050
t.Fatal(err)
5151
}
@@ -59,7 +59,7 @@ func TestSuccess(t *testing.T) {
5959
// Expect client to register for conf.
6060
confIntent := ctx.AssertRegisterConf(false)
6161

62-
testSuccess(ctx, testRequest.Amount, *hash,
62+
testSuccess(ctx, testRequest.Amount, info.SwapHash,
6363
signalPrepaymentResult, signalSwapPaymentResult, false,
6464
confIntent,
6565
)
@@ -72,7 +72,7 @@ func TestFailOffchain(t *testing.T) {
7272

7373
ctx := createClientTestContext(t, nil)
7474

75-
_, _, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
75+
_, err := ctx.swapClient.LoopOut(context.Background(), testRequest)
7676
if err != nil {
7777
t.Fatal(err)
7878
}
@@ -110,7 +110,7 @@ func TestFailWrongAmount(t *testing.T) {
110110
// Modify mock for this subtest.
111111
modifier(ctx.serverMock)
112112

113-
_, _, err := ctx.swapClient.LoopOut(
113+
_, err := ctx.swapClient.LoopOut(
114114
context.Background(), testRequest,
115115
)
116116
if err != expectedErr {

interface.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ type LoopInSwapInfo struct { // nolint
250250
HtlcAddressNP2WSH btcutil.Address
251251
}
252252

253+
// LoopOutSwapInfo contains essential information of a loop-out swap after the
254+
// swap is initiated.
255+
type LoopOutSwapInfo struct { // nolint:golint
256+
// SwapHash contains the sha256 hash of the swap preimage.
257+
SwapHash lntypes.Hash
258+
259+
// HtlcAddressP2WSH contains the native segwit swap htlc address that
260+
// the server will publish to.
261+
HtlcAddressP2WSH btcutil.Address
262+
}
263+
253264
// SwapInfoKit contains common swap info fields.
254265
type SwapInfoKit struct {
255266
// Hash is the sha256 hash of the preimage that unlocks the htlcs. It

loopd/swapclient_server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
103103
req.OutgoingChanSet = in.OutgoingChanSet
104104
}
105105

106-
hash, htlc, err := s.impl.LoopOut(ctx, req)
106+
info, err := s.impl.LoopOut(ctx, req)
107107
if err != nil {
108108
log.Errorf("LoopOut: %v", err)
109109
return nil, err
110110
}
111111

112112
return &looprpc.SwapResponse{
113-
Id: hash.String(),
114-
IdBytes: hash[:],
115-
HtlcAddress: htlc.String(),
116-
HtlcAddressP2Wsh: htlc.String(),
113+
Id: info.SwapHash.String(),
114+
IdBytes: info.SwapHash[:],
115+
HtlcAddress: info.HtlcAddressP2WSH.String(),
116+
HtlcAddressP2Wsh: info.HtlcAddressP2WSH.String(),
117117
}, nil
118118
}
119119

0 commit comments

Comments
 (0)