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:
TheCharlatan
2023-04-17 22:20:59 +02:00
parent 401453df41
commit ba8fc7d788
78 changed files with 288 additions and 229 deletions

View File

@@ -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(