aboutsummaryrefslogtreecommitdiff
path: root/src/chainparams.cpp
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-04-17 22:20:59 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-05-09 15:49:14 +0200
commitba8fc7d788932b25864fb260ca14983aa2398c23 (patch)
tree3049d9b5282c243faf7e0ab1e7d2a7ee17937a36 /src/chainparams.cpp
parent401453df419af35957ec711423ac3d93ad512fe8 (diff)
downloadbitcoin-ba8fc7d788932b25864fb260ca14983aa2398c23.tar.xz
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/chainparams.cpp')
-rw-r--r--src/chainparams.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index d3d358a3f0..cc0e6e17d5 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -12,6 +12,7 @@
#include <hash.h> // for signet block challenge hash
#include <logging.h>
#include <script/interpreter.h>
+#include <util/chaintype.h>
#include <util/string.h>
#include <assert.h>
@@ -97,26 +98,29 @@ const CChainParams &Params() {
return *globalChainParams;
}
-std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
+std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain)
{
- if (chain == CBaseChainParams::MAIN) {
+ switch (chain) {
+ case ChainType::MAIN:
return CChainParams::Main();
- } else if (chain == CBaseChainParams::TESTNET) {
+ case ChainType::TESTNET:
return CChainParams::TestNet();
- } else if (chain == CBaseChainParams::SIGNET) {
+ case ChainType::SIGNET: {
auto opts = CChainParams::SigNetOptions{};
ReadSigNetArgs(args, opts);
return CChainParams::SigNet(opts);
- } else if (chain == CBaseChainParams::REGTEST) {
+ }
+ case ChainType::REGTEST: {
auto opts = CChainParams::RegTestOptions{};
ReadRegTestArgs(args, opts);
return CChainParams::RegTest(opts);
}
- throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
+ }
+ throw std::invalid_argument(strprintf("%s: Invalid ChainType value", __func__));
}
-void SelectParams(const std::string& network)
+void SelectParams(const ChainType chain)
{
- SelectBaseParams(network);
- globalChainParams = CreateChainParams(gArgs, network);
+ SelectBaseParams(chain);
+ globalChainParams = CreateChainParams(gArgs, chain);
}