Skip to content

Commit 0395cd8

Browse files
committed
loopd: move asset client to config
1 parent 3d1d859 commit 0395cd8

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{}),
@@ -471,7 +470,7 @@ func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error {
471470
func (s *Client) resumeSwaps(ctx context.Context,
472471
loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) {
473472

474-
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient)
473+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient)
475474

476475
for _, pend := range loopOutSwaps {
477476
if pend.State().State.Type() != loopdb.StateTypePending {
@@ -528,7 +527,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
528527

529528
// Verify that if we have an asset id set, we have a valid asset
530529
// client to use.
531-
if s.assetClient == nil {
530+
if s.AssetClient == nil {
532531
return nil, errors.New("asset client must be set " +
533532
"when using an asset id")
534533
}
@@ -563,7 +562,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
563562

564563
// Create a new swap object for this swap.
565564
swapCfg := newSwapConfig(
566-
s.lndServices, s.Store, s.Server, s.assetClient,
565+
s.lndServices, s.Store, s.Server, s.AssetClient,
567566
)
568567

569568
initResult, err := newLoopOutSwap(
@@ -745,7 +744,7 @@ func (s *Client) LoopIn(globalCtx context.Context,
745744

746745
// Create a new swap object for this swap.
747746
initiationHeight := s.executor.height()
748-
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient)
747+
swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient)
749748
initResult, err := newLoopInSwap(
750749
globalCtx, swapCfg, initiationHeight, request,
751750
)
@@ -964,7 +963,7 @@ func (s *Client) AbandonSwap(ctx context.Context,
964963
func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
965964
request *LoopOutQuoteRequest) (*LoopOutRfq, error) {
966965

967-
if s.assetClient == nil {
966+
if s.AssetClient == nil {
968967
return nil, errors.New("asset client must be set " +
969968
"when trying to loop out with an asset")
970969
}
@@ -978,7 +977,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
978977
}
979978

980979
// First we'll get the prepay rfq.
981-
prepayRfq, err := s.assetClient.GetRfqForAsset(
980+
prepayRfq, err := s.AssetClient.GetRfqForAsset(
982981
ctx, quote.PrepayAmount, rfqReq.AssetId,
983982
rfqReq.AssetEdgeNode, rfqReq.Expiry,
984983
rfqReq.MaxLimitMultiplier,
@@ -999,7 +998,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
999998
invoiceAmt := request.Amount + quote.SwapFee -
1000999
quote.PrepayAmount
10011000

1002-
swapRfq, err := s.assetClient.GetRfqForAsset(
1001+
swapRfq, err := s.AssetClient.GetRfqForAsset(
10031002
ctx, invoiceAmt, rfqReq.AssetId,
10041003
rfqReq.AssetEdgeNode, rfqReq.Expiry,
10051004
rfqReq.MaxLimitMultiplier,
@@ -1016,7 +1015,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
10161015
}
10171016

10181017
// We'll also want the asset name to verify for the client.
1019-
assetName, err := s.assetClient.GetAssetName(
1018+
assetName, err := s.AssetClient.GetAssetName(
10201019
ctx, rfqReq.AssetId,
10211020
)
10221021
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)