mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopin: refactor LoopIn to return struct instead of tuple
This commit is contained in:
parent
0c01e95433
commit
7a44eec36f
3 changed files with 23 additions and 8 deletions
12
client.go
12
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
|
||||
|
|
|
|||
11
interface.go
11
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue