2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-08 01:10:29 +00:00
loop/loopd/utils.go
2020-04-27 16:30:44 +02:00

47 lines
1.0 KiB
Go

package loopd
import (
"os"
"path/filepath"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/lndclient"
)
// getClient returns an instance of the swap client.
func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client,
func(), error) {
storeDir, err := getStoreDir(config.Network)
if err != nil {
return nil, nil, err
}
clientConfig := &loop.ClientConfig{
ServerAddress: config.SwapServer,
ProxyAddress: config.Proxy,
Insecure: config.Insecure,
TLSPathServer: config.TLSPathSwapSrv,
Lnd: lnd,
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
}
swapClient, cleanUp, err := loop.NewClient(storeDir, clientConfig)
if err != nil {
return nil, nil, err
}
return swapClient, cleanUp, nil
}
func getStoreDir(network string) (string, error) {
dir := filepath.Join(loopDirBase, network)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return "", err
}
return dir, nil
}