diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/util.cpp b/src/util.cpp index 8b36c3e5f7..393cc413d6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -736,28 +736,34 @@ fs::path GetConfigFile(const std::string& confPath) return AbsPathForConfigVal(fs::path(confPath), false); } -void ArgsManager::ReadConfigFile(const std::string& confPath) +void ArgsManager::ReadConfigStream(std::istream& stream) { - fs::ifstream streamConfig(GetConfigFile(confPath)); - if (!streamConfig.good()) - return; // No bitcoin.conf file is OK + LOCK(cs_args); + std::set<std::string> setOptions; + setOptions.insert("*"); + + for (boost::program_options::detail::config_file_iterator it(stream, setOptions), end; it != end; ++it) { - LOCK(cs_args); - std::set<std::string> setOptions; - setOptions.insert("*"); + // Don't overwrite existing settings so command line settings override bitcoin.conf + std::string strKey = std::string("-") + it->string_key; + std::string strValue = it->value[0]; + InterpretNegatedOption(strKey, strValue); + if (mapArgs.count(strKey) == 0) + mapArgs[strKey] = strValue; + mapMultiArgs[strKey].push_back(strValue); + } +} - for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it) - { - // Don't overwrite existing settings so command line settings override bitcoin.conf - std::string strKey = std::string("-") + it->string_key; - std::string strValue = it->value[0]; - InterpretNegatedOption(strKey, strValue); - if (mapArgs.count(strKey) == 0) - mapArgs[strKey] = strValue; - mapMultiArgs[strKey].push_back(strValue); - } +void ArgsManager::ReadConfigFile(const std::string& confPath) +{ + fs::ifstream stream(GetConfigFile(confPath)); + + // ok to not have a config file + if (stream.good()) { + ReadConfigStream(stream); } + // If datadir is changed in .conf file: ClearDatadirCache(); if (!fs::is_directory(GetDataDir(false))) { @@ -765,6 +771,20 @@ void ArgsManager::ReadConfigFile(const std::string& confPath) } } +std::string ArgsManager::GetChainName() const +{ + bool fRegTest = GetBoolArg("-regtest", false); + bool fTestNet = GetBoolArg("-testnet", false); + + if (fTestNet && fRegTest) + throw std::runtime_error("Invalid combination of -regtest and -testnet."); + if (fRegTest) + return CBaseChainParams::REGTEST; + if (fTestNet) + return CBaseChainParams::TESTNET; + return CBaseChainParams::MAIN; +} + #ifndef WIN32 fs::path GetPidFile() { |