diff options
author | TheCharlatan <seb.kung@gmail.com> | 2023-04-17 22:20:59 +0200 |
---|---|---|
committer | TheCharlatan <seb.kung@gmail.com> | 2023-05-09 15:49:14 +0200 |
commit | ba8fc7d788932b25864fb260ca14983aa2398c23 (patch) | |
tree | 3049d9b5282c243faf7e0ab1e7d2a7ee17937a36 /src/bitcoin-cli.cpp | |
parent | 401453df419af35957ec711423ac3d93ad512fe8 (diff) |
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.
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r-- | src/bitcoin-cli.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 63ba6a935d..a66134128d 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -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 { |