refactor: Replace string chain name constants with ChainTypes
This commit effectively moves the definition of these constants out of the chainparamsbase to their own file. Using the ChainType enums provides better type safety compared to passing around strings. The commit is part of an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager and other functionality that should not be part of the kernel library.
This commit is contained in:
78 files changed
+288
-229
No files matched your search
+1
-1
@@ -601,7 +601,7 @@ int GuiMain(int argc, char* argv[])
|
||||
PaymentServer::ipcParseCommandLine(argc, argv);
|
||||
#endif
|
||||
|
||||
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().NetworkIDString()));
|
||||
QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(Params().GetChainType()));
|
||||
assert(!networkStyle.isNull());
|
||||
// Allow for separate UI settings for testnets
|
||||
QApplication::setApplicationName(networkStyle->getAppName());
|
||||
|
||||
+13
-12
@@ -21,6 +21,7 @@
|
||||
#include <protocol.h>
|
||||
#include <script/script.h>
|
||||
#include <script/standard.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/fs.h>
|
||||
#include <util/fs_helpers.h>
|
||||
@@ -503,12 +504,12 @@ bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
|
||||
#ifdef WIN32
|
||||
fs::path static StartupShortcutPath()
|
||||
{
|
||||
std::string chain = gArgs.GetChainName();
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
ChainType chain = gArgs.GetChainType();
|
||||
if (chain == ChainType::MAIN)
|
||||
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";
|
||||
if (chain == CBaseChainParams::TESTNET) // Remove this special case when CBaseChainParams::TESTNET = "testnet4"
|
||||
if (chain == ChainType::TESTNET) // Remove this special case when testnet CBaseChainParams::DataDir() is incremented to "testnet4"
|
||||
return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk";
|
||||
return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", chain));
|
||||
return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", ChainTypeToString(chain)));
|
||||
}
|
||||
|
||||
bool GetStartOnSystemStartup()
|
||||
@@ -541,7 +542,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||
// Start client minimized
|
||||
QString strArgs = "-min";
|
||||
// Set -testnet /-regtest options
|
||||
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
|
||||
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainTypeString()));
|
||||
|
||||
// Set the path to the shortcut target
|
||||
psl->SetPath(pszExePath);
|
||||
@@ -586,10 +587,10 @@ fs::path static GetAutostartDir()
|
||||
|
||||
fs::path static GetAutostartFilePath()
|
||||
{
|
||||
std::string chain = gArgs.GetChainName();
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
ChainType chain = gArgs.GetChainType();
|
||||
if (chain == ChainType::MAIN)
|
||||
return GetAutostartDir() / "bitcoin.desktop";
|
||||
return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", chain));
|
||||
return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", ChainTypeToString(chain)));
|
||||
}
|
||||
|
||||
bool GetStartOnSystemStartup()
|
||||
@@ -629,15 +630,15 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
||||
std::ofstream optionFile{GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc};
|
||||
if (!optionFile.good())
|
||||
return false;
|
||||
std::string chain = gArgs.GetChainName();
|
||||
ChainType chain = gArgs.GetChainType();
|
||||
// Write a bitcoin.desktop file to the autostart directory:
|
||||
optionFile << "[Desktop Entry]\n";
|
||||
optionFile << "Type=Application\n";
|
||||
if (chain == CBaseChainParams::MAIN)
|
||||
if (chain == ChainType::MAIN)
|
||||
optionFile << "Name=Bitcoin\n";
|
||||
else
|
||||
optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
|
||||
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
|
||||
optionFile << strprintf("Name=Bitcoin (%s)\n", ChainTypeToString(chain));
|
||||
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", ChainTypeToString(chain));
|
||||
optionFile << "Terminal=false\n";
|
||||
optionFile << "Hidden=false\n";
|
||||
optionFile.close();
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@
|
||||
#include <chainparams.h>
|
||||
#include <qt/intro.h>
|
||||
#include <qt/forms/ui_intro.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <util/fs.h>
|
||||
|
||||
#include <qt/guiconstants.h>
|
||||
@@ -219,7 +220,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB)
|
||||
{
|
||||
/* Use selectParams here to guarantee Params() can be used by node interface */
|
||||
try {
|
||||
SelectParams(gArgs.GetChainName());
|
||||
SelectParams(gArgs.GetChainType());
|
||||
} catch (const std::exception&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,20 @@
|
||||
|
||||
#include <chainparamsbase.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/chaintype.h>
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
static const struct {
|
||||
const char *networkId;
|
||||
const ChainType networkId;
|
||||
const char *appName;
|
||||
const int iconColorHueShift;
|
||||
const int iconColorSaturationReduction;
|
||||
} network_styles[] = {
|
||||
{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
|
||||
{"test", QAPP_APP_NAME_TESTNET, 70, 30},
|
||||
{"signet", QAPP_APP_NAME_SIGNET, 35, 15},
|
||||
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30},
|
||||
{ChainType::MAIN, QAPP_APP_NAME_DEFAULT, 0, 0},
|
||||
{ChainType::TESTNET, QAPP_APP_NAME_TESTNET, 70, 30},
|
||||
{ChainType::SIGNET, QAPP_APP_NAME_SIGNET, 35, 15},
|
||||
{ChainType::REGTEST, QAPP_APP_NAME_REGTEST, 160, 30},
|
||||
};
|
||||
|
||||
// titleAddText needs to be const char* for tr()
|
||||
@@ -77,9 +78,9 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
|
||||
trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
|
||||
}
|
||||
|
||||
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
|
||||
const NetworkStyle* NetworkStyle::instantiate(const ChainType networkId)
|
||||
{
|
||||
std::string titleAddText = networkId == CBaseChainParams::MAIN ? "" : strprintf("[%s]", networkId);
|
||||
std::string titleAddText = networkId == ChainType::MAIN ? "" : strprintf("[%s]", ChainTypeToString(networkId));
|
||||
for (const auto& network_style : network_styles) {
|
||||
if (networkId == network_style.networkId) {
|
||||
return new NetworkStyle(
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#ifndef BITCOIN_QT_NETWORKSTYLE_H
|
||||
#define BITCOIN_QT_NETWORKSTYLE_H
|
||||
|
||||
#include <util/chaintype.h>
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
@@ -14,7 +16,7 @@ class NetworkStyle
|
||||
{
|
||||
public:
|
||||
/** Get style associated with provided network id, or 0 if not known */
|
||||
static const NetworkStyle* instantiate(const std::string& networkId);
|
||||
static const NetworkStyle* instantiate(const ChainType networkId);
|
||||
|
||||
const QString &getAppName() const { return appName; }
|
||||
const QIcon &getAppIcon() const { return appIcon; }
|
||||
|
||||
@@ -744,7 +744,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
|
||||
ui->dataDir->setText(model->dataDir());
|
||||
ui->blocksDir->setText(model->blocksDir());
|
||||
ui->startupTime->setText(model->formatClientStartupTime());
|
||||
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
|
||||
ui->networkName->setText(QString::fromStdString(Params().GetChainTypeString()));
|
||||
|
||||
//Setup autocomplete and attach it
|
||||
QStringList wordList;
|
||||
|
||||
@@ -73,7 +73,7 @@ void AppTests::appTests()
|
||||
qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>("interfaces::BlockAndHeaderTipInfo");
|
||||
m_app.parameterSetup();
|
||||
QVERIFY(m_app.createOptionsModel(/*resetSettings=*/true));
|
||||
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().NetworkIDString()));
|
||||
QScopedPointer<const NetworkStyle> style(NetworkStyle::instantiate(Params().GetChainType()));
|
||||
m_app.setupPlatformStyle();
|
||||
m_app.createWindow(style.data());
|
||||
connect(&m_app, &BitcoinApplication::windowShown, this, &AppTests::guiTests);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <qt/test/rpcnestedtests.h>
|
||||
#include <qt/test/uritests.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <qt/test/addressbooktests.h>
|
||||
@@ -57,7 +58,7 @@ int main(int argc, char* argv[])
|
||||
//
|
||||
// All tests must use their own testing setup (if needed).
|
||||
fs::create_directories([] {
|
||||
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
|
||||
BasicTestingSetup dummy{ChainType::REGTEST};
|
||||
return gArgs.GetDataDirNet() / "blocks";
|
||||
}());
|
||||
|
||||
|
||||
Reference in new issue
Block a user