From 6d008095750dd9fb700f5ad2c2e709fcf7d4bc96 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 16 Apr 2019 19:18:28 -0700 Subject: [PATCH] cmd/loopd+lndclient: based on the network, update the macaron path if unset --- cmd/loopd/daemon.go | 3 ++- lndclient/lnd_services.go | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/cmd/loopd/daemon.go b/cmd/loopd/daemon.go index e9008a9..5d8060a 100644 --- a/cmd/loopd/daemon.go +++ b/cmd/loopd/daemon.go @@ -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 diff --git a/lndclient/lnd_services.go b/lndclient/lnd_services.go index 8350d6f..244c26d 100644 --- a/lndclient/lnd_services.go +++ b/lndclient/lnd_services.go @@ -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)