mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: move asset client to config
This commit is contained in:
parent
9f7249f14f
commit
a10b483096
2 changed files with 11 additions and 10 deletions
19
client.go
19
client.go
|
|
@ -103,7 +103,6 @@ type Client struct {
|
||||||
lndServices *lndclient.LndServices
|
lndServices *lndclient.LndServices
|
||||||
sweeper *sweep.Sweeper
|
sweeper *sweep.Sweeper
|
||||||
executor *executor
|
executor *executor
|
||||||
assetClient *assets.TapdClient
|
|
||||||
|
|
||||||
resumeReady chan struct{}
|
resumeReady chan struct{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
|
@ -196,6 +195,7 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
|
||||||
CreateExpiryTimer: func(d time.Duration) <-chan time.Time {
|
CreateExpiryTimer: func(d time.Duration) <-chan time.Time {
|
||||||
return time.NewTimer(d).C
|
return time.NewTimer(d).C
|
||||||
},
|
},
|
||||||
|
AssetClient: cfg.AssetClient,
|
||||||
LoopOutMaxParts: cfg.LoopOutMaxParts,
|
LoopOutMaxParts: cfg.LoopOutMaxParts,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +286,6 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore,
|
||||||
errChan: make(chan error),
|
errChan: make(chan error),
|
||||||
clientConfig: *config,
|
clientConfig: *config,
|
||||||
lndServices: cfg.Lnd,
|
lndServices: cfg.Lnd,
|
||||||
assetClient: cfg.AssetClient,
|
|
||||||
sweeper: sweeper,
|
sweeper: sweeper,
|
||||||
executor: executor,
|
executor: executor,
|
||||||
resumeReady: make(chan struct{}),
|
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,
|
func (s *Client) resumeSwaps(ctx context.Context,
|
||||||
loopOutSwaps []*loopdb.LoopOut, loopInSwaps []*loopdb.LoopIn) {
|
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 {
|
for _, pend := range loopOutSwaps {
|
||||||
if pend.State().State.Type() != loopdb.StateTypePending {
|
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
|
// Verify that if we have an asset id set, we have a valid asset
|
||||||
// client to use.
|
// client to use.
|
||||||
if s.assetClient == nil {
|
if s.AssetClient == nil {
|
||||||
return nil, errors.New("asset client must be set " +
|
return nil, errors.New("asset client must be set " +
|
||||||
"when using an asset id")
|
"when using an asset id")
|
||||||
}
|
}
|
||||||
|
|
@ -559,7 +558,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
|
||||||
|
|
||||||
// Create a new swap object for this swap.
|
// Create a new swap object for this swap.
|
||||||
swapCfg := newSwapConfig(
|
swapCfg := newSwapConfig(
|
||||||
s.lndServices, s.Store, s.Server, s.assetClient,
|
s.lndServices, s.Store, s.Server, s.AssetClient,
|
||||||
)
|
)
|
||||||
|
|
||||||
initResult, err := newLoopOutSwap(
|
initResult, err := newLoopOutSwap(
|
||||||
|
|
@ -741,7 +740,7 @@ func (s *Client) LoopIn(globalCtx context.Context,
|
||||||
|
|
||||||
// Create a new swap object for this swap.
|
// Create a new swap object for this swap.
|
||||||
initiationHeight := s.executor.height()
|
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(
|
initResult, err := newLoopInSwap(
|
||||||
globalCtx, swapCfg, initiationHeight, request,
|
globalCtx, swapCfg, initiationHeight, request,
|
||||||
)
|
)
|
||||||
|
|
@ -960,7 +959,7 @@ func (s *Client) AbandonSwap(ctx context.Context,
|
||||||
func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
|
func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
|
||||||
request *LoopOutQuoteRequest) (*LoopOutRfq, error) {
|
request *LoopOutQuoteRequest) (*LoopOutRfq, error) {
|
||||||
|
|
||||||
if s.assetClient == nil {
|
if s.AssetClient == nil {
|
||||||
return nil, errors.New("asset client must be set " +
|
return nil, errors.New("asset client must be set " +
|
||||||
"when trying to loop out with an asset")
|
"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.
|
// First we'll get the prepay rfq.
|
||||||
prepayRfq, err := s.assetClient.GetRfqForAsset(
|
prepayRfq, err := s.AssetClient.GetRfqForAsset(
|
||||||
ctx, quote.PrepayAmount, rfqReq.AssetId,
|
ctx, quote.PrepayAmount, rfqReq.AssetId,
|
||||||
rfqReq.AssetEdgeNode, rfqReq.Expiry,
|
rfqReq.AssetEdgeNode, rfqReq.Expiry,
|
||||||
rfqReq.MaxLimitMultiplier,
|
rfqReq.MaxLimitMultiplier,
|
||||||
|
|
@ -995,7 +994,7 @@ func (s *Client) getAssetRfq(ctx context.Context, quote *LoopOutQuote,
|
||||||
invoiceAmt := request.Amount + quote.SwapFee -
|
invoiceAmt := request.Amount + quote.SwapFee -
|
||||||
quote.PrepayAmount
|
quote.PrepayAmount
|
||||||
|
|
||||||
swapRfq, err := s.assetClient.GetRfqForAsset(
|
swapRfq, err := s.AssetClient.GetRfqForAsset(
|
||||||
ctx, invoiceAmt, rfqReq.AssetId,
|
ctx, invoiceAmt, rfqReq.AssetId,
|
||||||
rfqReq.AssetEdgeNode, rfqReq.Expiry,
|
rfqReq.AssetEdgeNode, rfqReq.Expiry,
|
||||||
rfqReq.MaxLimitMultiplier,
|
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.
|
// 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,
|
ctx, rfqReq.AssetId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/lightninglabs/aperture/l402"
|
"github.com/lightninglabs/aperture/l402"
|
||||||
"github.com/lightninglabs/lndclient"
|
"github.com/lightninglabs/lndclient"
|
||||||
|
"github.com/lightninglabs/loop/assets"
|
||||||
"github.com/lightninglabs/loop/loopdb"
|
"github.com/lightninglabs/loop/loopdb"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
@ -15,6 +16,7 @@ type clientConfig struct {
|
||||||
Server swapServerClient
|
Server swapServerClient
|
||||||
Conn *grpc.ClientConn
|
Conn *grpc.ClientConn
|
||||||
Store loopdb.SwapStore
|
Store loopdb.SwapStore
|
||||||
|
AssetClient *assets.TapdClient
|
||||||
L402Store l402.Store
|
L402Store l402.Store
|
||||||
CreateExpiryTimer func(expiry time.Duration) <-chan time.Time
|
CreateExpiryTimer func(expiry time.Duration) <-chan time.Time
|
||||||
LoopOutMaxParts uint32
|
LoopOutMaxParts uint32
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue