Skip to content

Commit 7a44eec

Browse files
committed
loopin: refactor LoopIn to return struct instead of tuple
1 parent 0c01e95 commit 7a44eec

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

client.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,15 @@ func (s *Client) waitForInitialized(ctx context.Context) error {
464464

465465
// LoopIn initiates a loop in swap.
466466
func (s *Client) LoopIn(globalCtx context.Context,
467-
request *LoopInRequest) (*lntypes.Hash, btcutil.Address, error) {
467+
request *LoopInRequest) (*LoopInSwapInfo, error) {
468468

469469
log.Infof("Loop in %v (last hop: %v)",
470470
request.Amount,
471471
request.LastHop,
472472
)
473473

474474
if err := s.waitForInitialized(globalCtx); err != nil {
475-
return nil, nil, err
475+
return nil, err
476476
}
477477

478478
// Create a new swap object for this swap.
@@ -486,15 +486,19 @@ func (s *Client) LoopIn(globalCtx context.Context,
486486
globalCtx, &swapCfg, initiationHeight, request,
487487
)
488488
if err != nil {
489-
return nil, nil, err
489+
return nil, err
490490
}
491491

492492
// Post swap to the main loop.
493493
s.executor.initiateSwap(globalCtx, swap)
494494

495495
// Return hash so that the caller can identify this swap in the updates
496496
// stream.
497-
return &swap.hash, swap.htlc.Address, nil
497+
swapInfo := &LoopInSwapInfo{
498+
SwapHash: swap.hash,
499+
HtlcAddress: swap.htlc.Address,
500+
}
501+
return swapInfo, nil
498502
}
499503

500504
// LoopInQuote takes an amount and returns a break down of estimated

interface.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ type LoopInQuote struct {
235235
CltvDelta int32
236236
}
237237

238+
// LoopInSwapInfo contains essential information of a loop-in swap after the
239+
// swap is initiated.
240+
type LoopInSwapInfo struct { // nolint
241+
// SwapHash contains the sha256 hash of the swap preimage.
242+
SwapHash lntypes.Hash
243+
244+
// HtlcAddress contains the swap htlc address, where the loop-in
245+
// funds will be paid.
246+
HtlcAddress btcutil.Address
247+
}
248+
238249
// SwapInfoKit contains common swap info fields.
239250
type SwapInfoKit struct {
240251
// Hash is the sha256 hash of the preimage that unlocks the htlcs. It

loopd/swapclient_server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,16 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
409409
}
410410
req.LastHop = &lastHop
411411
}
412-
hash, htlc, err := s.impl.LoopIn(ctx, req)
412+
swapInfo, err := s.impl.LoopIn(ctx, req)
413413
if err != nil {
414414
log.Errorf("Loop in: %v", err)
415415
return nil, err
416416
}
417417

418418
return &looprpc.SwapResponse{
419-
Id: hash.String(),
420-
IdBytes: hash[:],
421-
HtlcAddress: htlc.String(),
419+
Id: swapInfo.SwapHash.String(),
420+
IdBytes: swapInfo.SwapHash[:],
421+
HtlcAddress: swapInfo.HtlcAddress.String(),
422422
}, nil
423423
}
424424

0 commit comments

Comments
 (0)