mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
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:
@@ -20,6 +20,7 @@
|
||||
#include <rpc/request.h>
|
||||
#include <tinyformat.h>
|
||||
#include <univalue.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
@@ -73,10 +74,10 @@ static void SetupCliArgs(ArgsManager& argsman)
|
||||
{
|
||||
SetupHelpOptions(argsman);
|
||||
|
||||
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
|
||||
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
|
||||
const auto signetBaseParams = CreateBaseChainParams(CBaseChainParams::SIGNET);
|
||||
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
|
||||
const auto defaultBaseParams = CreateBaseChainParams(ChainType::MAIN);
|
||||
const auto testnetBaseParams = CreateBaseChainParams(ChainType::TESTNET);
|
||||
const auto signetBaseParams = CreateBaseChainParams(ChainType::SIGNET);
|
||||
const auto regtestBaseParams = CreateBaseChainParams(ChainType::REGTEST);
|
||||
|
||||
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
@@ -174,7 +175,7 @@ static int AppInitRPC(int argc, char* argv[])
|
||||
}
|
||||
// Check for chain settings (BaseParams() calls are only valid after this clause)
|
||||
try {
|
||||
SelectBaseParams(gArgs.GetChainName());
|
||||
SelectBaseParams(gArgs.GetChainType());
|
||||
} catch (const std::exception& e) {
|
||||
tfm::format(std::cerr, "Error: %s\n", e.what());
|
||||
return EXIT_FAILURE;
|
||||
@@ -426,10 +427,16 @@ private:
|
||||
std::vector<Peer> m_peers;
|
||||
std::string ChainToString() const
|
||||
{
|
||||
if (gArgs.GetChainName() == CBaseChainParams::TESTNET) return " testnet";
|
||||
if (gArgs.GetChainName() == CBaseChainParams::SIGNET) return " signet";
|
||||
if (gArgs.GetChainName() == CBaseChainParams::REGTEST) return " regtest";
|
||||
return "";
|
||||
switch (gArgs.GetChainType()) {
|
||||
case ChainType::TESTNET:
|
||||
return " testnet";
|
||||
case ChainType::SIGNET:
|
||||
return " signet";
|
||||
case ChainType::REGTEST:
|
||||
return " regtest";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
std::string PingTimeToString(double seconds) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user