Skip to content

Commit 005ad26

Browse files
committed
ArgsManager: special handling for -regtest and -testnet
1 parent 608415d commit 005ad26

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/util.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,22 @@ class ArgsManagerHelper {
537537

538538
return found_result;
539539
}
540+
541+
/* Special test for -testnet and -regtest args, because we
542+
* don't want to be confused by craziness like "[regtest] testnet=1"
543+
*/
544+
static inline bool GetNetBoolArg(const ArgsManager &am, const std::string& net_arg)
545+
{
546+
std::pair<bool,std::string> found_result(false,std::string());
547+
found_result = GetArgHelper(am.m_override_args, net_arg, true);
548+
if (!found_result.first) {
549+
found_result = GetArgHelper(am.m_config_args, net_arg, true);
550+
if (!found_result.first) {
551+
return false; // not set
552+
}
553+
}
554+
return InterpretBool(found_result.second); // is set, so evaluate
555+
}
540556
};
541557

542558
/**
@@ -950,8 +966,8 @@ void ArgsManager::ReadConfigFile(const std::string& confPath)
950966

951967
std::string ArgsManager::GetChainName() const
952968
{
953-
bool fRegTest = GetBoolArg("-regtest", false);
954-
bool fTestNet = GetBoolArg("-testnet", false);
969+
bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
970+
bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
955971

956972
if (fTestNet && fRegTest)
957973
throw std::runtime_error("Invalid combination of -regtest and -testnet.");

0 commit comments

Comments
 (0)