Skip to content

Commit 28d1692

Browse files
committed
loopd: move asset client to config
1 parent fc88a10 commit 28d1692

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

client.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ type Client struct {
103103
lndServices *lndclient.LndServices
104104
sweeper *sweep.Sweeper
105105
executor *executor
106-
assetClient *assets.TapdClient
107106

108107
resumeReady chan struct{}
109108
wg sync.WaitGroup
@@ -196,6 +195,7 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
196195
CreateExpiryTimer: func(d time.Duration) <-chan time.Time {
197196
return time.NewTimer(d).C
198197
},
198+
AssetClient: cfg.AssetClient,
199199
LoopOutMaxParts: cfg.LoopOutMaxParts,
200200
}
201201

@@ -286,7 +286,6 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
286286
errChan: make(chan error),
287287
clientConfig: *config,
288288
lndServices: cfg.Lnd,
289-
assetClient: cfg.AssetClient,
290289
sweeper: sweeper,
291290
executor: executor,
292291
resumeReady: make(chan struct{}),
@@ -467,7 +466,7 @@ func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
467466
func (s *Client) resumeSwaps(ctx context.Context,
468467
loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) {
469468

470-
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient)
469+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient)
471470

472471
for _, pend := range loopOutSwaps {
473472
if pend.State().State.Type() != loopdb.StateTypePending {
@@ -524,7 +523,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
524523

525524
// Verify that if we have an asset id set, we have a valid asset
526525
// client to use.
527-
if s.assetClient == nil {
526+
if s.AssetClient == nil {
528527
return nil, errors.New("asset client must be set " +
529528
"when using an asset id")
530529
}
@@ -559,7 +558,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
559558

560559
// Create a new swap object for this swap.
561560
swapCfg := newSwapConfig(
562-
s.lndServices, s.Store, s.Server, s.assetClient,
561+
s.lndServices, s.Store, s.Server, s.AssetClient,
563562
)
564563

565564
initResult, err := newLoopOutSwap(
@@ -741,7 +740,7 @@ func (s *Client) LoopIn(globalCtx context.Context,
741740

742741
// Create a new swap object for this swap.
743742
initiationHeight := s.executor.height()
744-
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient)
743+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient)
745744
initResult, err := newLoopInSwap(
746745
globalCtx, swapCfg, initiationHeight, request,
747746
)
@@ -960,7 +959,7 @@ func (s *Client) AbandonSwap(ctx context.Context,
960959
func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
961960
request *LoopOutQuoteRequest) (*LoopOutRfq, error) {
962961

963-
if s.assetClient == nil {
962+
if s.AssetClient == nil {
964963
return nil, errors.New("asset client must be set " +
965964
"when trying to loop out with an asset")
966965
}
@@ -974,7 +973,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
974973
}
975974

976975
// First we'll get the prepay rfq.
977-
prepayRfq, err := s.assetClient.GetRfqForAsset(
976+
prepayRfq, err := s.AssetClient.GetRfqForAsset(
978977
ctx, quote.PrepayAmount, rfqReq.AssetId,
979978
rfqReq.AssetEdgeNode, rfqReq.Expiry,
980979
rfqReq.MaxLimitMultiplier,
@@ -995,7 +994,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
995994
invoiceAmt := request.Amount + quote.SwapFee -
996995
quote.PrepayAmount
997996

998-
swapRfq, err := s.assetClient.GetRfqForAsset(
997+
swapRfq, err := s.AssetClient.GetRfqForAsset(
999998
ctx, invoiceAmt, rfqReq.AssetId,
1000999
rfqReq.AssetEdgeNode, rfqReq.Expiry,
10011000
rfqReq.MaxLimitMultiplier,
@@ -1012,7 +1011,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
10121011
}
10131012

10141013
// We'll also want the asset name to verify for the client.
1015-
assetName, err := s.assetClient.GetAssetName(
1014+
assetName, err := s.AssetClient.GetAssetName(
10161015
ctx, rfqReq.AssetId,
10171016
)
10181017
if err != nil {

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/lightninglabs/aperture/l402"
77
"github.com/lightninglabs/lndclient"
8+
"github.com/lightninglabs/loop/assets"
89
"github.com/lightninglabs/loop/loopdb"
910
"google.golang.org/grpc"
1011
)
@@ -15,6 +16,7 @@ type clientConfig struct {
1516
Server swapServerClient
1617
Conn *grpc.ClientConn
1718
Store loopdb.SwapStore
19+
AssetClient *assets.TapdClient
1820
L402Store l402.Store
1921
CreateExpiryTimer func(expiry time.Duration) <-chan time.Time
2022
LoopOutMaxParts uint32

0 commit comments

Comments
 (0)