config: provide default value for lnd macaroon path
To make it easier for users with everything installed to the default
locations to use Pool, we add a default value for the macaroon path.
@@ -77,6 +77,17 @@ var (
DefaultMacaroonPath = filepath.Join(
DefaultBaseDir, DefaultNetwork, DefaultMacaroonFilename,
)
+
+ // DefaultLndDir is the default location where we look for lnd's tls and
+ // macaroon files.
+ DefaultLndDir = btcutil.AppDataDir("lnd", false)
+
+ // DefaultLndMacaroonPath is the default location where we look for a
+ // macaroon to use when connecting to lnd.
+ DefaultLndMacaroonPath = filepath.Join(
+ DefaultLndDir, "data", "chain", "bitcoin", DefaultNetwork,
+ defaultLndMacaroon,
+ )
)
type LndConfig struct {
@@ -174,6 +185,7 @@ func DefaultConfig() Config {
MacaroonPath: DefaultMacaroonPath,
Lnd: &LndConfig{
Host: "localhost:10009",
+ MacaroonPath: DefaultLndMacaroonPath,
},
}
}
@@ -258,7 +270,9 @@ func Validate(cfg *Config) error {
// Make sure only one of the macaroon options is used.
switch {
- case cfg.Lnd.MacaroonPath != "" && cfg.Lnd.MacaroonDir != "":
+ case cfg.Lnd.MacaroonPath != DefaultLndMacaroonPath &&
+ cfg.Lnd.MacaroonDir != "":
+
return fmt.Errorf("use --lnd.macaroonpath only")
case cfg.Lnd.MacaroonDir != "":
@@ -280,6 +294,17 @@ func Validate(cfg *Config) error {
return fmt.Errorf("must specify --lnd.macaroonpath")
}
+ // Adjust the default lnd macaroon path if only the network is
+ // specified.
+ if cfg.Network != DefaultNetwork &&
+ cfg.Lnd.MacaroonPath == DefaultLndMacaroonPath {
+
+ cfg.Lnd.MacaroonPath = path.Join(
+ DefaultLndDir, "data", "chain", "bitcoin", cfg.Network,
+ defaultLndMacaroon,
+ )
+ }
+
return nil
}
