From d229a1a6072cb0bfbd6aa2e7e97c39e91519e9e1 Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 18 Aug 2020 21:35:46 +0200 Subject: [PATCH 1/2] config: add default network value --- loopd/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopd/config.go b/loopd/config.go index fad68db..957f85e 100644 --- a/loopd/config.go +++ b/loopd/config.go @@ -13,6 +13,7 @@ import ( var ( loopDirBase = btcutil.AppDataDir("loop", false) + defaultNetwork = "mainnet" defaultLogLevel = "info" defaultLogDirname = "logs" defaultLogFilename = "loopd.log" @@ -75,7 +76,7 @@ const ( // DefaultConfig returns all default values for the Config struct. func DefaultConfig() Config { return Config{ - Network: "mainnet", + Network: defaultNetwork, RPCListen: "localhost:11010", RESTListen: "localhost:8081", Server: &loopServerConfig{ From ed04120a1ab26e8e37ee90719eb31c05d756b349 Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 18 Aug 2020 21:42:13 +0200 Subject: [PATCH 2/2] loopd: set network in default config path --- loopd/config.go | 4 +++- loopd/run.go | 34 +++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/loopd/config.go b/loopd/config.go index 957f85e..feb40dd 100644 --- a/loopd/config.go +++ b/loopd/config.go @@ -18,7 +18,9 @@ var ( defaultLogDirname = "logs" defaultLogFilename = "loopd.log" defaultLogDir = filepath.Join(loopDirBase, defaultLogDirname) - defaultConfigFile = filepath.Join(loopDirBase, defaultConfigFilename) + defaultConfigFile = filepath.Join( + loopDirBase, defaultNetwork, defaultConfigFilename, + ) defaultMaxLogFiles = 3 defaultMaxLogFileSize = 10 diff --git a/loopd/run.go b/loopd/run.go index 52f45b9..6317a11 100644 --- a/loopd/run.go +++ b/loopd/run.go @@ -137,17 +137,7 @@ func Run(rpcCfg RPCConfig) error { // Parse ini file. loopDir := lncfg.CleanAndExpandPath(config.LoopDir) - configFile := lncfg.CleanAndExpandPath(config.ConfigFile) - - // If our loop directory is set and the config file parameter is not - // set, we assume that they want to point to a config file in their - // loop dir. However, if the config file has a non-default value, then - // we leave the config parameter as its custom value. - if loopDir != loopDirBase && configFile == defaultConfigFile { - configFile = filepath.Join( - loopDir, defaultConfigFilename, - ) - } + configFile := getConfigPath(config, loopDir) if err := flags.IniParse(configFile, &config); err != nil { // If it's a parsing related error, then we'll return @@ -237,3 +227,25 @@ func Run(rpcCfg RPCConfig) error { return fmt.Errorf("unimplemented command %v", parser.Active.Name) } + +// getConfigPath gets our config path based on the values that are set in our +// config. +func getConfigPath(cfg Config, loopDir string) string { + // If the config file path provided by the user is set, then we just + // use this value. + if cfg.ConfigFile != defaultConfigFile { + return lncfg.CleanAndExpandPath(cfg.ConfigFile) + } + + // If the user has set a loop directory that is different to the default + // we will use this loop directory as the location of our config file. + // We do not namespace by network, because this is a custom loop dir. + if loopDir != loopDirBase { + return filepath.Join(loopDir, defaultConfigFilename) + } + + // Otherwise, we are using our default loop directory, and the user did + // not set a config file path. We use our default loop dir, namespaced + // by network. + return filepath.Join(loopDir, cfg.Network, defaultConfigFilename) +}