mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
137 lines
5.6 KiB
C++
137 lines
5.6 KiB
C++
// Copyright (c) 2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <chainparamsseeds.h>
|
|
#include <common/args.h>
|
|
#include <consensus/merkle.h>
|
|
#include <deploymentinfo.h>
|
|
#include <hash.h> // for signet block challenge hash
|
|
#include <issuance.h>
|
|
#include <primitives/transaction.h>
|
|
#include <logging.h>
|
|
#include <script/interpreter.h>
|
|
#include <util/string.h>
|
|
#include <crypto/sha256.h>
|
|
|
|
#include <assert.h>
|
|
|
|
void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
|
|
{
|
|
if (args.IsArgSet("-signetseednode")) {
|
|
options.seeds.emplace(args.GetArgs("-signetseednode"));
|
|
}
|
|
if (args.IsArgSet("-signetchallenge")) {
|
|
const auto signet_challenge = args.GetArgs("-signetchallenge");
|
|
if (signet_challenge.size() != 1) {
|
|
throw std::runtime_error(strprintf("%s: -signetchallenge cannot be multiple values.", __func__));
|
|
}
|
|
options.challenge.emplace(ParseHex(signet_challenge[0]));
|
|
}
|
|
}
|
|
|
|
void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
|
|
{
|
|
if (auto value = args.GetBoolArg("-fastprune")) options.fastprune = *value;
|
|
|
|
for (const std::string& arg : args.GetArgs("-testactivationheight")) {
|
|
const auto found{arg.find('@')};
|
|
if (found == std::string::npos) {
|
|
throw std::runtime_error(strprintf("Invalid format (%s) for -testactivationheight=name@height.", arg));
|
|
}
|
|
|
|
const auto value{arg.substr(found + 1)};
|
|
int32_t height;
|
|
if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits<int>::max()) {
|
|
throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg));
|
|
}
|
|
|
|
const auto deployment_name{arg.substr(0, found)};
|
|
if (const auto buried_deployment = GetBuriedDeployment(deployment_name)) {
|
|
options.activation_heights[*buried_deployment] = height;
|
|
} else {
|
|
throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
|
|
}
|
|
}
|
|
|
|
if (!args.IsArgSet("-vbparams")) return;
|
|
|
|
for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
|
|
std::vector<std::string> vDeploymentParams = SplitString(strDeployment, ':');
|
|
if (vDeploymentParams.size() < 3 || 4 < vDeploymentParams.size()) {
|
|
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]");
|
|
}
|
|
CChainParams::VersionBitsParameters vbparams{};
|
|
if (!ParseInt64(vDeploymentParams[1], &vbparams.start_time)) {
|
|
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
|
|
}
|
|
if (!ParseInt64(vDeploymentParams[2], &vbparams.timeout)) {
|
|
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
|
|
}
|
|
if (vDeploymentParams.size() >= 4) {
|
|
if (!ParseInt32(vDeploymentParams[3], &vbparams.min_activation_height)) {
|
|
throw std::runtime_error(strprintf("Invalid min_activation_height (%s)", vDeploymentParams[3]));
|
|
}
|
|
} else {
|
|
vbparams.min_activation_height = 0;
|
|
}
|
|
bool found = false;
|
|
for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
|
|
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
|
|
options.version_bits_parameters[Consensus::DeploymentPos(j)] = vbparams;
|
|
found = true;
|
|
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d\n", vDeploymentParams[0], vbparams.start_time, vbparams.timeout, vbparams.min_activation_height);
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
|
|
}
|
|
}
|
|
}
|
|
|
|
static std::unique_ptr<const CChainParams> globalChainParams;
|
|
|
|
const CChainParams &Params() {
|
|
assert(globalChainParams);
|
|
return *globalChainParams;
|
|
}
|
|
|
|
std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain)
|
|
{
|
|
// Reserved names for non-custom chains
|
|
if (chain == CBaseChainParams::MAIN) {
|
|
return CChainParams::Main();
|
|
} else if (chain == CBaseChainParams::TESTNET) {
|
|
return CChainParams::TestNet();
|
|
} else if (chain == CBaseChainParams::SIGNET) {
|
|
auto opts = CChainParams::SigNetOptions{};
|
|
ReadSigNetArgs(args, opts);
|
|
return CChainParams::SigNet(opts);
|
|
} else if (chain == CBaseChainParams::REGTEST) {
|
|
auto opts = CChainParams::RegTestOptions{};
|
|
ReadRegTestArgs(args, opts);
|
|
return CChainParams::RegTest(opts);
|
|
} else if (chain == CBaseChainParams::LIQUID1) {
|
|
return CChainParams::LiquidV1(args);
|
|
} else if (chain == CBaseChainParams::LIQUID1TEST) {
|
|
return CChainParams::LiquidV1Test(args);
|
|
} else if (chain == CBaseChainParams::LIQUIDTESTNET) {
|
|
auto opts = CChainParams::RegTestOptions{};
|
|
ReadRegTestArgs(args, opts);
|
|
return CChainParams::LiquidTestNet(chain, args, opts);
|
|
}
|
|
|
|
auto opts = CChainParams::RegTestOptions{};
|
|
ReadRegTestArgs(args, opts);
|
|
return CChainParams::Custom(chain, args, opts);
|
|
}
|
|
|
|
void SelectParams(const std::string& network)
|
|
{
|
|
SelectBaseParams(network);
|
|
globalChainParams = CreateChainParams(gArgs, network);
|
|
}
|