Skip to content

Commit 750c2fb

Browse files
author
MarcoFalke
committed
Merge #16680: Preparations for more testchains
3bf9d8c Testchains: Qt: Simplify network/chain styles (Jorge Timón) 052c54e Testchains: Generic selection with -chain=<str> in addition of -testnet and -regtest (Jorge Timón) Pull request description: Separated from #8994 as suggested by MarcoFalke and Sjors in bitcoin/bitcoin#8994 (comment) You can't really test the qt changes on their own, so to test them, use #8994 . ACKs for top commit: MarcoFalke: ACK 3bf9d8c Tree-SHA512: 5b5e6083ebc0a44505a507fac633e7af18037c85e5e73f5d1e6f7e730575d3297ba8a31d1c2441df623b273f061c32d8fa324f4aa6bead01d23e88582029b568
2 parents 33c466a + 3bf9d8c commit 750c2fb

File tree

11 files changed

+29
-24
lines changed

11 files changed

+29
-24
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static int AppInitRPC(int argc, char* argv[])
133133
tfm::format(std::cerr, "Error reading configuration file: %s\n", error.c_str());
134134
return EXIT_FAILURE;
135135
}
136-
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
136+
// Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
137137
try {
138138
SelectBaseParams(gArgs.GetChainName());
139139
} catch (const std::exception& e) {

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int AppInitRawTx(int argc, char* argv[])
8888
return EXIT_FAILURE;
8989
}
9090

91-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
91+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
9292
try {
9393
SelectParams(gArgs.GetChainName());
9494
} catch (const std::exception& e) {

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static bool AppInit(int argc, char* argv[])
101101
if (!gArgs.ReadConfigFiles(error, true)) {
102102
return InitError(strprintf("Error reading configuration file: %s\n", error));
103103
}
104-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
104+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
105105
try {
106106
SelectParams(gArgs.GetChainName());
107107
} catch (const std::exception& e) {

src/chainparamsbase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const std::string CBaseChainParams::REGTEST = "regtest";
1717

1818
void SetupChainParamsBaseOptions()
1919
{
20+
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2021
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
21-
"This is intended for regression testing tools and app development.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
22+
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2223
gArgs.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
23-
gArgs.AddArg("-testnet", "Use the test chain", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
24+
gArgs.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2425
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2526
}
2627

src/qt/bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ int GuiMain(int argc, char* argv[])
511511
// - QSettings() will use the new application name after this, resulting in network-specific settings
512512
// - Needs to be done before createOptionsModel
513513

514-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
514+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
515515
try {
516516
node->selectParams(gArgs.GetChainName());
517517
} catch(std::exception &e) {
@@ -524,7 +524,7 @@ int GuiMain(int argc, char* argv[])
524524
PaymentServer::ipcParseCommandLine(*node, argc, argv);
525525
#endif
526526

527-
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
527+
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
528528
assert(!networkStyle.isNull());
529529
// Allow for separate UI settings for testnets
530530
QApplication::setApplicationName(networkStyle->getAppName());

src/qt/guiutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
588588
// Start client minimized
589589
QString strArgs = "-min";
590590
// Set -testnet /-regtest options
591-
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
591+
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
592592

593593
// Set the path to the shortcut target
594594
psl->SetPath(pszExePath);
@@ -683,7 +683,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
683683
optionFile << "Name=Bitcoin\n";
684684
else
685685
optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
686-
optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
686+
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
687687
optionFile << "Terminal=false\n";
688688
optionFile << "Hidden=false\n";
689689
optionFile.close();

src/qt/networkstyle.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
#include <qt/guiconstants.h>
88

9+
#include <chainparamsbase.h>
10+
#include <tinyformat.h>
11+
912
#include <QApplication>
1013

1114
static const struct {
1215
const char *networkId;
1316
const char *appName;
1417
const int iconColorHueShift;
1518
const int iconColorSaturationReduction;
16-
const char *titleAddText;
1719
} network_styles[] = {
18-
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
19-
{"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
20-
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30, "[regtest]"}
20+
{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
21+
{"test", QAPP_APP_NAME_TESTNET, 70, 30},
22+
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30}
2123
};
2224
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
2325

@@ -75,8 +77,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
7577
trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
7678
}
7779

78-
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
80+
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
7981
{
82+
std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId);
8083
for (unsigned x=0; x<network_styles_count; ++x)
8184
{
8285
if (networkId == network_styles[x].networkId)
@@ -85,7 +88,7 @@ const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
8588
network_styles[x].appName,
8689
network_styles[x].iconColorHueShift,
8790
network_styles[x].iconColorSaturationReduction,
88-
network_styles[x].titleAddText);
91+
titleAddText.c_str());
8992
}
9093
}
9194
return nullptr;

src/qt/networkstyle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NetworkStyle
1414
{
1515
public:
1616
/** Get style associated with provided BIP70 network id, or 0 if not known */
17-
static const NetworkStyle *instantiate(const QString &networkId);
17+
static const NetworkStyle* instantiate(const std::string& networkId);
1818

1919
const QString &getAppName() const { return appName; }
2020
const QIcon &getAppIcon() const { return appIcon; }

src/qt/test/apptests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void AppTests::appTests()
6868

6969
m_app.parameterSetup();
7070
m_app.createOptionsModel(true /* reset settings */);
71-
QScopedPointer<const NetworkStyle> style(
72-
NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
71+
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString()));
7372
m_app.setupPlatformStyle();
7473
m_app.createWindow(style.data());
7574
connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests);

src/test/util_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup)
913913
// Results file is formatted like:
914914
//
915915
// <input> || <output>
916-
BOOST_CHECK_EQUAL(out_sha_hex, "b284f4b4a15dd6bf8c06213a69a004b1960388e1d9917173927db52ac220927f");
916+
BOOST_CHECK_EQUAL(out_sha_hex, "94b4ad55c8ac639a56b93e36f7e32e4c611fd7d7dd7b2be6a71707b1eadcaec7");
917917
}
918918

919919
BOOST_AUTO_TEST_CASE(util_FormatMoney)

0 commit comments

Comments
 (0)