2020-01-03 13:01:31 +00:00
|
|
|
package loopd
|
2019-03-06 20:13:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-01-10 11:13:39 +00:00
|
|
|
"github.com/btcsuite/btcutil"
|
2019-03-07 04:32:24 +00:00
|
|
|
"github.com/lightninglabs/loop"
|
2019-03-06 23:29:44 +00:00
|
|
|
"github.com/lightninglabs/loop/lndclient"
|
2019-03-06 20:13:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// getClient returns an instance of the swap client.
|
2020-01-10 11:13:39 +00:00
|
|
|
func getClient(config *config, lnd *lndclient.LndServices) (*loop.Client,
|
|
|
|
func(), error) {
|
2019-03-07 04:32:24 +00:00
|
|
|
|
2020-01-10 11:13:39 +00:00
|
|
|
storeDir, err := getStoreDir(config.Network)
|
2019-03-06 20:13:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-07 04:32:24 +00:00
|
|
|
swapClient, cleanUp, err := loop.NewClient(
|
2020-01-10 11:13:39 +00:00
|
|
|
storeDir, config.SwapServer, config.Insecure,
|
|
|
|
config.TLSPathSwapSrv, lnd, btcutil.Amount(config.MaxLSATCost),
|
|
|
|
btcutil.Amount(config.MaxLSATFee),
|
2019-03-06 20:13:50 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return swapClient, cleanUp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStoreDir(network string) (string, error) {
|
2019-03-07 10:37:28 +00:00
|
|
|
dir := filepath.Join(loopDirBase, network)
|
2019-03-06 20:13:50 +00:00
|
|
|
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir, nil
|
|
|
|
}
|