From a10b4830962c7a3592f725192da780f3128a2fc2 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Mon, 17 Feb 2025 15:58:33 +0100 Subject: [PATCH] loopd: move asset client to config --- client.go | 19 +++++++++---------- config.go | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 2e2bb122..e4a55290 100644 --- a/client.go +++ b/client.go @@ -103,7 +103,6 @@ type Client struct { lndServices *lndclient.LndServices sweeper *sweep.Sweeper executor *executor - assetClient *assets.TapdClient resumeReady chan struct{} wg sync.WaitGroup @@ -196,6 +195,7 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore, CreateExpiryTimer: func(d time.Duration) <-chan time.Time { return time.NewTimer(d).C }, + AssetClient: cfg.AssetClient, LoopOutMaxParts: cfg.LoopOutMaxParts, } @@ -286,7 +286,6 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore, errChan: make(chan error), clientConfig: *config, lndServices: cfg.Lnd, - assetClient: cfg.AssetClient, sweeper: sweeper, executor: executor, resumeReady: make(chan struct{}), @@ -467,7 +466,7 @@ func (s *Client) Run(ctx context.Context, statusChan chan<- SwapInfo) error { func (s *Client) resumeSwaps(ctx context.Context, loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) { - swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient) + swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient) for _, pend := range loopOutSwaps { if pend.State().State.Type() != loopdb.StateTypePending { @@ -524,7 +523,7 @@ func (s *Client) LoopOut(globalCtx context.Context, // Verify that if we have an asset id set, we have a valid asset // client to use. - if s.assetClient == nil { + if s.AssetClient == nil { return nil, errors.New("asset client must be set " + "when using an asset id") } @@ -559,7 +558,7 @@ func (s *Client) LoopOut(globalCtx context.Context, // Create a new swap object for this swap. swapCfg := newSwapConfig( - s.lndServices, s.Store, s.Server, s.assetClient, + s.lndServices, s.Store, s.Server, s.AssetClient, ) initResult, err := newLoopOutSwap( @@ -741,7 +740,7 @@ func (s *Client) LoopIn(globalCtx context.Context, // Create a new swap object for this swap. initiationHeight := s.executor.height() - swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.assetClient) + swapCfg := newSwapConfig(s.lndServices, s.Store, s.Server, s.AssetClient) initResult, err := newLoopInSwap( globalCtx, swapCfg, initiationHeight, request, ) @@ -960,7 +959,7 @@ func (s *Client) AbandonSwap(ctx context.Context, func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote, request *LoopOutQuoteRequest) (*LoopOutRfq, error) { - if s.assetClient == nil { + if s.AssetClient == nil { return nil, errors.New("asset client must be set " + "when trying to loop out with an asset") } @@ -974,7 +973,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote, } // First we'll get the prepay rfq. - prepayRfq, err := s.assetClient.GetRfqForAsset( + prepayRfq, err := s.AssetClient.GetRfqForAsset( ctx, quote.PrepayAmount, rfqReq.AssetId, rfqReq.AssetEdgeNode, rfqReq.Expiry, rfqReq.MaxLimitMultiplier, @@ -995,7 +994,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote, invoiceAmt := request.Amount + quote.SwapFee - quote.PrepayAmount - swapRfq, err := s.assetClient.GetRfqForAsset( + swapRfq, err := s.AssetClient.GetRfqForAsset( ctx, invoiceAmt, rfqReq.AssetId, rfqReq.AssetEdgeNode, rfqReq.Expiry, rfqReq.MaxLimitMultiplier, @@ -1012,7 +1011,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote, } // We'll also want the asset name to verify for the client. - assetName, err := s.assetClient.GetAssetName( + assetName, err := s.AssetClient.GetAssetName( ctx, rfqReq.AssetId, ) if err != nil { diff --git a/config.go b/config.go index 6cf47c1d..af337828 100644 --- a/config.go +++ b/config.go @@ -5,6 +5,7 @@ import ( "github.com/lightninglabs/aperture/l402" "github.com/lightninglabs/lndclient" + "github.com/lightninglabs/loop/assets" "github.com/lightninglabs/loop/loopdb" "google.golang.org/grpc" ) @@ -15,6 +16,7 @@ type clientConfig struct { Server swapServerClient Conn *grpc.ClientConn Store loopdb.SwapStore + AssetClient *assets.TapdClient L402Store l402.Store CreateExpiryTimer func(expiry time.Duration) <-chan time.Time LoopOutMaxParts uint32