loopd: move asset client to config

This commit is contained in:
sputn1ck 2025-02-17 15:58:33 +01:00
parent 9f7249f14f
commit a10b483096
No known key found for this signature in database
GPG key ID: 671103D881A5F0E4
2 changed files with 11 additions and 10 deletions

View file

@ -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 {

View file

@ -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