loop/loopd/utils.go

58 lines
1.5 KiB
Go
Raw Normal View History

package loopd
2019-03-06 21:13:50 +01:00
import (
"context"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/liquidity"
"github.com/lightningnetwork/lnd/clock"
2019-03-06 21:13:50 +01:00
)
// getClient returns an instance of the swap client.
2020-05-15 12:17:57 +02:00
func getClient(config *Config, lnd *lndclient.LndServices) (*loop.Client,
func(), error) {
2020-04-27 14:03:23 +02:00
clientConfig := &loop.ClientConfig{
ServerAddress: config.Server.Host,
ProxyAddress: config.Server.Proxy,
SwapServerNoTLS: config.Server.NoTLS,
TLSPathServer: config.Server.TLSPath,
2020-05-12 09:31:50 +02:00
Lnd: lnd,
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
LoopOutMaxParts: config.LoopOutMaxParts,
2020-04-27 14:03:23 +02:00
}
swapClient, cleanUp, err := loop.NewClient(config.DataDir, clientConfig)
2019-03-06 21:13:50 +01:00
if err != nil {
return nil, nil, err
}
return swapClient, cleanUp, nil
}
func getLiquidityManager(client *loop.Client) *liquidity.Manager {
mngrCfg := &liquidity.Config{
LoopOutRestrictions: func(ctx context.Context) (
*liquidity.Restrictions, error) {
outTerms, err := client.Server.GetLoopOutTerms(ctx)
if err != nil {
return nil, err
}
return liquidity.NewRestrictions(
outTerms.MinSwapAmount, outTerms.MaxSwapAmount,
), nil
},
Lnd: client.LndServices,
Clock: clock.NewDefaultClock(),
ListLoopOut: client.Store.FetchLoopOutSwaps,
ListLoopIn: client.Store.FetchLoopInSwaps,
}
return liquidity.NewManager(mngrCfg)
}