From 7a44eec36fde4a4008091132973b060142a76c7d Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Wed, 29 Apr 2020 18:30:44 +0200 Subject: [PATCH] loopin: refactor LoopIn to return struct instead of tuple --- client.go | 12 ++++++++---- interface.go | 11 +++++++++++ loopd/swapclient_server.go | 8 ++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index d5eece9..720b99b 100644 --- a/client.go +++ b/client.go @@ -464,7 +464,7 @@ func (s *Client) waitForInitialized(ctx context.Context) error { // LoopIn initiates a loop in swap. func (s *Client) LoopIn(globalCtx context.Context, - request *LoopInRequest) (*lntypes.Hash, btcutil.Address, error) { + request *LoopInRequest) (*LoopInSwapInfo, error) { log.Infof("Loop in %v (last hop: %v)", request.Amount, @@ -472,7 +472,7 @@ func (s *Client) LoopIn(globalCtx context.Context, ) if err := s.waitForInitialized(globalCtx); err != nil { - return nil, nil, err + return nil, err } // Create a new swap object for this swap. @@ -486,7 +486,7 @@ func (s *Client) LoopIn(globalCtx context.Context, globalCtx, &swapCfg, initiationHeight, request, ) if err != nil { - return nil, nil, err + return nil, err } // Post swap to the main loop. @@ -494,7 +494,11 @@ func (s *Client) LoopIn(globalCtx context.Context, // Return hash so that the caller can identify this swap in the updates // stream. - return &swap.hash, swap.htlc.Address, nil + swapInfo := &LoopInSwapInfo{ + SwapHash: swap.hash, + HtlcAddress: swap.htlc.Address, + } + return swapInfo, nil } // LoopInQuote takes an amount and returns a break down of estimated diff --git a/interface.go b/interface.go index 98850b8..e718178 100644 --- a/interface.go +++ b/interface.go @@ -235,6 +235,17 @@ type LoopInQuote struct { CltvDelta int32 } +// LoopInSwapInfo contains essential information of a loop-in swap after the +// swap is initiated. +type LoopInSwapInfo struct { // nolint + // SwapHash contains the sha256 hash of the swap preimage. + SwapHash lntypes.Hash + + // HtlcAddress contains the swap htlc address, where the loop-in + // funds will be paid. + HtlcAddress 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 c896d5c..f3528d9 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -409,16 +409,16 @@ func (s *swapClientServer) LoopIn(ctx context.Context, } req.LastHop = &lastHop } - hash, htlc, err := s.impl.LoopIn(ctx, req) + swapInfo, err := s.impl.LoopIn(ctx, req) if err != nil { log.Errorf("Loop in: %v", err) return nil, err } return &looprpc.SwapResponse{ - Id: hash.String(), - IdBytes: hash[:], - HtlcAddress: htlc.String(), + Id: swapInfo.SwapHash.String(), + IdBytes: swapInfo.SwapHash[:], + HtlcAddress: swapInfo.HtlcAddress.String(), }, nil }