2019-03-06 20:13:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// getLnd returns an instance of the lnd services proxy.
|
2019-03-07 10:37:28 +00:00
|
|
|
func getLnd(network string, cfg *lndConfig) (*lndclient.GrpcLndServices, error) {
|
|
|
|
return lndclient.NewLndServices(
|
2019-04-17 22:49:23 +00:00
|
|
|
cfg.Host, "client", network, cfg.MacaroonDir, cfg.TLSPath,
|
2019-03-06 20:13:50 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// getClient returns an instance of the swap client.
|
2019-11-08 09:00:02 +00:00
|
|
|
func getClient(network, swapServer string, insecure bool, tlsPathServer string,
|
2019-03-07 04:32:24 +00:00
|
|
|
lnd *lndclient.LndServices) (*loop.Client, func(), error) {
|
|
|
|
|
2019-03-06 20:13:50 +00:00
|
|
|
storeDir, err := getStoreDir(network)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-07 04:32:24 +00:00
|
|
|
swapClient, cleanUp, err := loop.NewClient(
|
2019-11-08 09:00:02 +00:00
|
|
|
storeDir, swapServer, insecure, tlsPathServer, lnd,
|
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
|
|
|
|
}
|