mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
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.
This commit is contained in:
parent
d938098398
commit
edabbc78a3
2 changed files with 29 additions and 4 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue