aboutsummaryrefslogtreecommitdiff
path: root/src/chainparams.cpp
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-05-09 15:23:32 +0100
committerfanquake <fanquake@gmail.com>2023-05-09 15:42:21 +0100
commitfc06881f13495154c888a64a38c7d538baf00435 (patch)
tree9be742027b5debdbd7c70d03b6c67a9efde05b3a /src/chainparams.cpp
parentd5ff96f92008b12660007327aa8dc87bc5f63897 (diff)
parentd168458d1ff987e0d741c75ac1d4b63ae0cfb7e7 (diff)
Merge bitcoin/bitcoin#27491: refactor: Move chain constants to the util library
d168458d1ff987e0d741c75ac1d4b63ae0cfb7e7 scripted-diff: Remove unused chainparamsbase includes (TheCharlatan) e9ee8aaf3acdf6dce2b339916d4c602484570050 Add missing definitions in prep for scripted diff (TheCharlatan) ba8fc7d788932b25864fb260ca14983aa2398c23 refactor: Replace string chain name constants with ChainTypes (TheCharlatan) 401453df419af35957ec711423ac3d93ad512fe8 refactor: Introduce ChainType getters for ArgsManager (TheCharlatan) bfc21c31b2186f7d30fc9a9ca7d6887ab61c6fb9 refactor: Create chaintype files (TheCharlatan) Pull request description: This pull request is part of the `libbitcoinkernel` project https://github.com/bitcoin/bitcoin/issues/24303 https://github.com/bitcoin/bitcoin/projects/18 and more specifically its "Step 2: Decouple most non-consensus code from libbitcoinkernel". It is also a follow up to #26177. It replaces pull request https://github.com/bitcoin/bitcoin/pull/27294, which just moved the constants to a new file, but did not re-declare them as enums. The code move of the chain name constants out of the `chainparamsbase` to their own separate header allows the kernel `chainparams` to no longer include `chainparamsbase`. The `chainparamsbase` contain references to the `ArgsManager` and networking related options that should not belong to the kernel library. Besides this move, the constants are re-declared as enums with helper functions facilitating string conversions. ACKs for top commit: ryanofsky: Code review ACK d168458d1ff987e0d741c75ac1d4b63ae0cfb7e7. Just suggested changes since last review. Tree-SHA512: ac2fbe5cbbab4f52eae1e30af1f16700b6589eb4764c328a151a712adfc37f326cc94a65c385534c57d4bc92cc1a13bf1777d92bc924a20dbb30440e7380b316
Diffstat (limited to 'src/chainparams.cpp')
-rw-r--r--src/chainparams.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index d3d358a3f0..f61bf01745 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -5,6 +5,7 @@
#include <chainparams.h>
+#include <chainparamsbase.h>
#include <chainparamsseeds.h>
#include <common/args.h>
#include <consensus/merkle.h>
@@ -12,6 +13,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 +99,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);
}