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/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

@ -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 {

@ -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

@ -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
}

Loading…
Cancel
Save