diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 1884d1c2a2..bd3ef610df 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -148,7 +148,7 @@ static int AppInitRPC(int argc, char* argv[]) tfm::format(std::cerr, "Error reading configuration file: %s\n", error); 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 9fc4c2f7b9..b589031665 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -88,7 +88,7 @@ static int AppInitRawTx(int argc, char* argv[]) return true; } - // 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 25c54be437..97b2b67531 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -88,7 +88,7 @@ static bool AppInit(int argc, char* argv[]) if (!args.ReadConfigFiles(error, true)) { return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error))); } - // 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(args.GetChainName()); } catch (const std::exception& e) { diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 74a9039c6f..9a6e33b982 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -32,9 +32,10 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman) argsman.AddArg("-llmqtestinstantsendparams=:", "Override the default LLMQ size for the LLMQ_TEST_INSTANTSEND quorums (default: 3:2, regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-powtargetspacing=", "Override the default PowTargetSpacing value in seconds (default: 2.5 minutes, devnet-only)", ArgsManager::ALLOW_INT, OptionsCategory::CHAINPARAMS); argsman.AddArg("-minimumdifficultyblocks=", "The number of blocks that can be mined with the minimum difficulty at the start of a chain (default: 0, devnet-only)", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); + argsman.AddArg("-chain=", "Use the chain (default: main). Allowed values: main, test, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.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.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); - argsman.AddArg("-testnet", "Use the test chain", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); + "This is intended for regression testing tools and app development. Equivalent to -chain=regtest", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); + argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS); argsman.AddArg("-vbparams=::(::(::))", "Use given start/end times for specified version bits deployment (regtest-only). " "Specifying window, threshold/thresholdstart, thresholdmin and falloffcoeff is optional.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 915863e84d..835cd9c417 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -541,7 +541,7 @@ int GuiMain(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) { @@ -559,7 +559,7 @@ int GuiMain(int argc, char* argv[]) return EXIT_FAILURE; } - QScopedPointer networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString()))); + QScopedPointer networkStyle(NetworkStyle::instantiate(Params().NetworkIDString())); assert(!networkStyle.isNull()); // Allow for separate UI settings for testnets // QApplication::setApplicationName(networkStyle->getAppName()); // moved to NetworkStyle::NetworkStyle diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 9ee068276f..d60a2d898e 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -838,7 +838,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())); // Set the path to the shortcut target psl->SetPath(pszExePath); @@ -933,7 +933,7 @@ bool SetStartOnSystemStartup(bool fAutoStart) optionFile << "Name=Dash Core\n"; else optionFile << strprintf("Name=Dash Core (%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/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index 47f8f3e7eb..cb0151e943 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include static const struct { @@ -22,9 +24,9 @@ static const struct { const std::string titleAddText; } network_styles[] = { {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""}, - {"test", QAPP_APP_NAME_TESTNET, 190, 20, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")}, + {"test", QAPP_APP_NAME_TESTNET, 190, 20}, {"devnet", QAPP_APP_NAME_DEVNET, 190, 20, "[devnet: %s]"}, - {"regtest", QAPP_APP_NAME_REGTEST, 160, 30, "[regtest]"} + {"regtest", QAPP_APP_NAME_REGTEST, 160, 30} }; void NetworkStyle::rotateColor(QColor& col, const int iconColorHueShift, const int iconColorSaturationReduction) @@ -86,8 +88,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, splashImage = QPixmap(":/images/splash"); } -const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) +const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId) { + std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId); for (const auto& network_style : network_styles) { if (networkId == network_style.networkId) @@ -95,7 +98,7 @@ const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) std::string appName = network_style.appName; std::string titleAddText = network_style.titleAddText; - if (networkId == QString(CBaseChainParams::DEVNET.c_str())) { + if (networkId == CBaseChainParams::DEVNET.c_str()) { appName = strprintf(appName, gArgs.GetDevNetName()); titleAddText = strprintf(titleAddText, gArgs.GetDevNetName()); } diff --git a/src/qt/networkstyle.h b/src/qt/networkstyle.h index 96f76a420d..a01964cc2a 100644 --- a/src/qt/networkstyle.h +++ b/src/qt/networkstyle.h @@ -15,7 +15,7 @@ class NetworkStyle { public: /** Get style associated with provided network id, or 0 if not known */ - static const NetworkStyle *instantiate(const QString &networkId); + static const NetworkStyle* instantiate(const std::string& networkId); const QString &getAppName() const { return appName; } const QIcon &getAppIcon() const { return appIcon; } diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index d4c4f38749..e2fdf0c49e 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -73,7 +73,7 @@ void AppTests::appTests() GUIUtil::loadFonts(); m_app.createOptionsModel(true /* reset settings */); QScopedPointer style( - NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString()))); + NetworkStyle::instantiate(Params().NetworkIDString())); m_app.createWindow(style.data()); connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests); expectCallback("guiTests"); diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 6eae590155..550d8b861c 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1135,7 +1135,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup) // Results file is formatted like: // // || - BOOST_CHECK_EQUAL(out_sha_hex, "f8cff01ad967dfc82cf71208aa2b60f01a0aa621c28356af5ca91d1d7370c217"); + BOOST_CHECK_EQUAL(out_sha_hex, "1cd2697d1665d086f15ed18b3333bc356c3d39ba490589dc58afd8fc2f457731"); } BOOST_AUTO_TEST_CASE(util_ReadWriteSettings) diff --git a/src/util/system.cpp b/src/util/system.cpp index 59bf0b1443..2c3d9c59b3 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -976,10 +976,11 @@ std::string ArgsManager::GetChainName() const const bool fRegTest = get_net("-regtest"); const bool fTestNet = get_net("-testnet"); const bool fDevNet = get_net("-devnet", false); + const bool is_chain_arg_set = IsArgSet("-chain"); - int nameParamsCount = (fRegTest ? 1 : 0) + (fDevNet ? 1 : 0) + (fTestNet ? 1 : 0); + int nameParamsCount = (fRegTest ? 1 : 0) + (fDevNet ? 1 : 0) + (fTestNet ? 1 : 0) + (is_chain_arg_set ? 1 : 0); if (nameParamsCount > 1) - throw std::runtime_error("Only one of -regtest, -testnet or -devnet can be used."); + throw std::runtime_error("Only one of -regtest, -testnet, -devnet or -chain can be used."); if (fDevNet) return CBaseChainParams::DEVNET; @@ -987,7 +988,7 @@ std::string ArgsManager::GetChainName() const return CBaseChainParams::REGTEST; if (fTestNet) return CBaseChainParams::TESTNET; - return CBaseChainParams::MAIN; + return GetArg("-chain", CBaseChainParams::MAIN); } std::string ArgsManager::GetDevNetName() const