2020-01-03 14:01:31 +01:00
|
|
|
package loopd
|
2019-03-06 21:13:50 +01:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
2020-01-10 12:13:39 +01:00
|
|
|
"github.com/btcsuite/btcutil"
|
2019-03-06 20:32:24 -08:00
|
|
|
"github.com/lightninglabs/loop"
|
2019-03-06 15:29:44 -08:00
|
|
|
"github.com/lightninglabs/loop/lndclient"
|
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,
|
2020-01-10 12:13:39 +01:00
|
|
|
func(), error) {
|
2019-03-06 20:32:24 -08:00
|
|
|
|
2020-01-10 12:13:39 +01:00
|
|
|
storeDir, err := getStoreDir(config.Network)
|
2019-03-06 21:13:50 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 14:03:23 +02:00
|
|
|
clientConfig := &loop.ClientConfig{
|
2020-06-15 11:04:37 +02:00
|
|
|
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(storeDir, clientConfig)
|
2019-03-06 21:13:50 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return swapClient, cleanUp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getStoreDir(network string) (string, error) {
|
2019-03-07 11:37:28 +01:00
|
|
|
dir := filepath.Join(loopDirBase, network)
|
2019-03-06 21:13:50 +01:00
|
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dir, nil
|
|
|
|
|
}
|