cmd/loopd+lndclient: based on the network, update the macaron path if unset

pull/45/head
Olaoluwa Osuntokun 5 years ago
parent 5f6ad1161b
commit 6d00809575
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2

@ -34,7 +34,8 @@ func daemon(config *config) error {
// Create an instance of the loop client library.
swapClient, cleanup, err := getClient(
config.Network, config.SwapServer, config.Insecure, &lnd.LndServices,
config.Network, config.SwapServer, config.Insecure,
&lnd.LndServices,
)
if err != nil {
return err

@ -41,10 +41,38 @@ type GrpcLndServices struct {
func NewLndServices(lndAddress, application, network, macaroonDir,
tlsPath string) (*GrpcLndServices, error) {
// If the macaroon directory isn't set, then we can't proceed as we
// need then to obtain the macaroons for all sub-servers.
// Based on the network, if the macaroon directory isn't set, then
// we'll use the expected default locations.
if macaroonDir == "" {
return nil, fmt.Errorf("macarooon dir must be set")
switch network {
case "testnet":
macaroonDir = filepath.Join(
defaultLndDir, defaultDataDir,
defaultChainSubDir, "bitcoin", "testnet",
)
case "mainnet":
macaroonDir = filepath.Join(
defaultLndDir, defaultDataDir,
defaultChainSubDir, "bitcoin", "mainnet",
)
case "simnet":
macaroonDir = filepath.Join(
defaultLndDir, defaultDataDir,
defaultChainSubDir, "bitcoin", "simnet",
)
case "regtest":
macaroonDir = filepath.Join(
defaultLndDir, defaultDataDir,
defaultChainSubDir, "bitcoin", "regtest",
)
default:
return nil, fmt.Errorf("unsupported network: %v",
network)
}
}
// Now that we've ensured our macaroon directory is set properly, we
@ -88,7 +116,7 @@ func NewLndServices(lndAddress, application, network, macaroonDir,
}
// With the network check passed, we'll now initialize the rest of the
// sub-sever connections, giving each of them their specific macaroon.
// sub-server connections, giving each of them their specific macaroon.
notifierClient := newChainNotifierClient(conn, macaroons.chainMac)
signerClient := newSignerClient(conn, macaroons.signerMac)
walletKitClient := newWalletKitClient(conn, macaroons.walletKitMac)

Loading…
Cancel
Save