diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index db713f58d2..a27845c315 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -129,7 +129,7 @@ static int AppInitRPC(int argc, char* argv[]) fprintf(stderr, "Error reading configuration file: %s\n", error.c_str()); return EXIT_FAILURE; } - // Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause) + // Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause) try { SelectBaseParams(gArgs.GetChainName()); } catch (const std::exception& e) { diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 5fef4724c9..be122afd19 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -86,7 +86,7 @@ static int AppInitRawTx(int argc, char* argv[]) return EXIT_FAILURE; } - // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(gArgs.GetChainName()); } catch (const std::exception& e) { diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 06f8622426..3548e66c34 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -98,7 +98,7 @@ static bool AppInit(int argc, char* argv[]) fprintf(stderr, "Error reading configuration file: %s\n", error.c_str()); return false; } - // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) try { SelectParams(gArgs.GetChainName()); } catch (const std::exception& e) { diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 870640e77d..1e70a3739e 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -17,6 +17,7 @@ const std::string CBaseChainParams::REGTEST = "regtest"; void SetupChainParamsBaseOptions() { + gArgs.AddArg("-chain=", "Use the chain (default: main). Allowed values: main, testnet, regtest", false, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. " "This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index d3ec67e441..d1b8e881d9 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -654,7 +654,7 @@ int main(int argc, char *argv[]) // - QSettings() will use the new application name after this, resulting in network-specific settings // - Needs to be done before createOptionsModel - // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) try { node->selectParams(gArgs.GetChainName()); } catch(std::exception &e) { diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index f8f031041c..09eae77908 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -562,7 +562,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) // Start client minimized QString strArgs = "-min"; // Set -testnet /-regtest options - strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false))); + strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName())); #ifdef UNICODE boost::scoped_array args(new TCHAR[strArgs.length() + 1]); @@ -672,7 +672,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) optionFile << "Name=Bitcoin\n"; else optionFile << strprintf("Name=Bitcoin (%s)\n", chain); - optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)); + optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain); optionFile << "Terminal=false\n"; optionFile << "Hidden=false\n"; optionFile.close(); diff --git a/src/util.cpp b/src/util.cpp index a391c5e857..de65703759 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -961,16 +961,18 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) std::string ArgsManager::GetChainName() const { - bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest"); - bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet"); + const bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest"); + const bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet"); + const bool is_chain_arg_set = IsArgSet("-chain"); - if (fTestNet && fRegTest) - throw std::runtime_error("Invalid combination of -regtest and -testnet."); + if ((int)is_chain_arg_set + (int)fRegTest + (int)fTestNet > 1) { + throw std::runtime_error("Invalid combination of -regtest, -testnet and -chain. Can use at most one."); + } if (fRegTest) return CBaseChainParams::REGTEST; if (fTestNet) return CBaseChainParams::TESTNET; - return CBaseChainParams::MAIN; + return GetArg("-chain", CBaseChainParams::MAIN); } #ifndef WIN32