Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | static inline std::pair<bool, std::string> GetArg(const ArgsManager &am, | ||||
found_result = GetArgHelper(am.m_config_args, arg); | found_result = GetArgHelper(am.m_config_args, arg); | ||||
if (found_result.first) { | if (found_result.first) { | ||||
return found_result; | return found_result; | ||||
} | } | ||||
} | } | ||||
return found_result; | return found_result; | ||||
} | } | ||||
/* Special test for -testnet and -regtest args, because we don't want to be | |||||
* confused by craziness like "[regtest] testnet=1" | |||||
*/ | |||||
static inline bool GetNetBoolArg(const ArgsManager &am, | |||||
const std::string &net_arg) { | |||||
std::pair<bool, std::string> found_result(false, std::string()); | |||||
found_result = GetArgHelper(am.m_override_args, net_arg, true); | |||||
if (!found_result.first) { | |||||
found_result = GetArgHelper(am.m_config_args, net_arg, true); | |||||
if (!found_result.first) { | |||||
// not set | |||||
return false; | |||||
} | |||||
} | |||||
// is set, so evaluate | |||||
return InterpretBool(found_result.second); | |||||
} | |||||
}; | }; | ||||
/** | /** | ||||
* Interpret -nofoo as if the user supplied -foo=0. | * Interpret -nofoo as if the user supplied -foo=0. | ||||
* | * | ||||
* This method also tracks when the -no form was supplied, and if so, checks | * This method also tracks when the -no form was supplied, and if so, checks | ||||
* whether there was a double-negative (-nofoo=0 -> -foo=1). | * whether there was a double-negative (-nofoo=0 -> -foo=1). | ||||
* | * | ||||
▲ Show 20 Lines • Show All 424 Lines • ▼ Show 20 Lines | void ArgsManager::ReadConfigFile(const std::string &confPath) { | ||||
if (!fs::is_directory(GetDataDir(false))) { | if (!fs::is_directory(GetDataDir(false))) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
strprintf("specified data directory \"%s\" does not exist.", | strprintf("specified data directory \"%s\" does not exist.", | ||||
gArgs.GetArg("-datadir", "").c_str())); | gArgs.GetArg("-datadir", "").c_str())); | ||||
} | } | ||||
} | } | ||||
std::string ArgsManager::GetChainName() const { | std::string ArgsManager::GetChainName() const { | ||||
bool fRegTest = GetBoolArg("-regtest", false); | bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest"); | ||||
bool fTestNet = GetBoolArg("-testnet", false); | bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet"); | ||||
if (fTestNet && fRegTest) { | if (fTestNet && fRegTest) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"Invalid combination of -regtest and -testnet."); | "Invalid combination of -regtest and -testnet."); | ||||
} | } | ||||
if (fRegTest) { | if (fRegTest) { | ||||
return CBaseChainParams::REGTEST; | return CBaseChainParams::REGTEST; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |