aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-03-10 17:21:05 -0500
committerTheCharlatan <seb.kung@gmail.com>2023-03-15 16:43:29 +0100
commitedabbc78a3bc272b2b802e1dbab73d6ed8e31e96 (patch)
treed72d36d2223e62db192710b4efa44155b6a61a6d /src
parentd938098398814f37fed9b018b44716179cfa4b03 (diff)
Add factory functions for Main/Test/Sig/Reg chainparams
This normalizes the behavior of initializing Main/Test/Sig/Reg chainparams with RegTest/SigNet chainparams. These factory functions can also easily be used from a context without an instantiated ArgsManager, e.g. from libbitcoin kernel code, unlike the existing CreateChainParams method.
Diffstat (limited to 'src')
-rw-r--r--src/chainparams.cpp28
-rw-r--r--src/chainparams.h5
2 files changed, 29 insertions, 4 deletions
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 2445c379eb..7130141c1c 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -582,20 +582,40 @@ const CChainParams &Params() {
return *globalChainParams;
}
+std::unique_ptr<const CChainParams> CChainParams::SigNet(const SigNetOptions& options)
+{
+ return std::make_unique<const SigNetParams>(options);
+}
+
+std::unique_ptr<const CChainParams> CChainParams::RegTest(const RegTestOptions& options)
+{
+ return std::make_unique<const CRegTestParams>(options);
+}
+
+std::unique_ptr<const CChainParams> CChainParams::Main()
+{
+ return std::make_unique<const CMainParams>();
+}
+
+std::unique_ptr<const CChainParams> CChainParams::TestNet()
+{
+ return std::make_unique<const CTestNetParams>();
+}
+
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
{
if (chain == CBaseChainParams::MAIN) {
- return std::unique_ptr<CChainParams>(new CMainParams());
+ return CChainParams::Main();
} else if (chain == CBaseChainParams::TESTNET) {
- return std::unique_ptr<CChainParams>(new CTestNetParams());
+ return CChainParams::TestNet();
} else if (chain == CBaseChainParams::SIGNET) {
auto opts = CChainParams::SigNetOptions{};
ReadSigNetArgs(args, opts);
- return std::make_unique<const SigNetParams>(opts);
+ return CChainParams::SigNet(opts);
} else if (chain == CBaseChainParams::REGTEST) {
auto opts = CChainParams::RegTestOptions{};
ReadRegTestArgs(args, opts);
- return std::make_unique<const CRegTestParams>(opts);
+ return CChainParams::RegTest(opts);
}
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
diff --git a/src/chainparams.h b/src/chainparams.h
index f2e2eb8bc0..30488510d7 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -151,6 +151,11 @@ public:
bool fastprune{false};
};
+ static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
+ static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
+ static std::unique_ptr<const CChainParams> Main();
+ static std::unique_ptr<const CChainParams> TestNet();
+
protected:
CChainParams() {}