2014-06-19 15:10:04 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-10-25 11:24:16 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-06-19 15:10:04 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "chainparamsbase.h"
|
|
|
|
|
2015-06-30 21:39:49 +02:00
|
|
|
#include "tinyformat.h"
|
2014-06-19 15:10:04 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
2014-08-28 22:56:53 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-06-30 21:39:49 +02:00
|
|
|
const std::string CBaseChainParams::MAIN = "main";
|
|
|
|
const std::string CBaseChainParams::TESTNET = "test";
|
2017-12-20 12:45:01 +01:00
|
|
|
const std::string CBaseChainParams::DEVNET = "dev";
|
2015-06-30 21:39:49 +02:00
|
|
|
const std::string CBaseChainParams::REGTEST = "regtest";
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2015-05-25 09:00:17 +02:00
|
|
|
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
|
|
|
|
{
|
|
|
|
strUsage += HelpMessageGroup(_("Chain selection options:"));
|
|
|
|
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
|
2018-03-02 14:12:31 +01:00
|
|
|
strUsage += HelpMessageOpt("-devnet=<name>", _("Use devnet chain with provided name"));
|
2015-05-25 09:00:17 +02:00
|
|
|
if (debugHelp) {
|
|
|
|
strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
|
|
|
|
"This is intended for regression testing tools and app development.");
|
|
|
|
}
|
|
|
|
}
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2014-10-25 11:24:16 +02:00
|
|
|
/**
|
|
|
|
* Main network
|
|
|
|
*/
|
2014-09-19 19:21:46 +02:00
|
|
|
class CBaseMainParams : public CBaseChainParams
|
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
public:
|
2014-09-19 19:21:46 +02:00
|
|
|
CBaseMainParams()
|
|
|
|
{
|
2015-04-14 20:27:45 +02:00
|
|
|
nRPCPort = 9998;
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
static CBaseMainParams mainParams;
|
|
|
|
|
2014-10-25 11:24:16 +02:00
|
|
|
/**
|
|
|
|
* Testnet (v3)
|
|
|
|
*/
|
2015-07-03 14:30:18 +02:00
|
|
|
class CBaseTestNetParams : public CBaseChainParams
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
public:
|
2014-09-19 19:21:46 +02:00
|
|
|
CBaseTestNetParams()
|
|
|
|
{
|
2015-04-14 20:27:45 +02:00
|
|
|
nRPCPort = 19998;
|
2014-06-19 15:10:04 +02:00
|
|
|
strDataDir = "testnet3";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static CBaseTestNetParams testNetParams;
|
|
|
|
|
2017-12-20 12:45:01 +01:00
|
|
|
/**
|
|
|
|
* Devnet
|
|
|
|
*/
|
|
|
|
class CBaseDevNetParams : public CBaseChainParams
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CBaseDevNetParams(const std::string &dataDir)
|
|
|
|
{
|
|
|
|
nRPCPort = 19998;
|
|
|
|
strDataDir = dataDir;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static CBaseDevNetParams *devNetParams;
|
|
|
|
|
2014-10-25 11:24:16 +02:00
|
|
|
/*
|
|
|
|
* Regression test
|
|
|
|
*/
|
2015-07-03 14:30:18 +02:00
|
|
|
class CBaseRegTestParams : public CBaseChainParams
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
public:
|
2014-09-19 19:21:46 +02:00
|
|
|
CBaseRegTestParams()
|
|
|
|
{
|
2015-07-03 14:30:18 +02:00
|
|
|
nRPCPort = 18332;
|
2014-06-19 15:10:04 +02:00
|
|
|
strDataDir = "regtest";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static CBaseRegTestParams regTestParams;
|
|
|
|
|
2014-09-19 19:21:46 +02:00
|
|
|
static CBaseChainParams* pCurrentBaseParams = 0;
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2014-09-19 19:21:46 +02:00
|
|
|
const CBaseChainParams& BaseParams()
|
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
assert(pCurrentBaseParams);
|
|
|
|
return *pCurrentBaseParams;
|
|
|
|
}
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
CBaseChainParams& BaseParams(const std::string& chain)
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2015-06-30 21:39:49 +02:00
|
|
|
if (chain == CBaseChainParams::MAIN)
|
2015-06-27 21:21:41 +02:00
|
|
|
return mainParams;
|
2015-06-30 21:39:49 +02:00
|
|
|
else if (chain == CBaseChainParams::TESTNET)
|
2015-06-27 21:21:41 +02:00
|
|
|
return testNetParams;
|
2017-12-20 12:45:01 +01:00
|
|
|
else if (chain == CBaseChainParams::DEVNET) {
|
|
|
|
assert(devNetParams);
|
|
|
|
return *devNetParams;
|
|
|
|
} else if (chain == CBaseChainParams::REGTEST)
|
2015-06-27 21:21:41 +02:00
|
|
|
return regTestParams;
|
2015-06-30 21:39:49 +02:00
|
|
|
else
|
|
|
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
void SelectBaseParams(const std::string& chain)
|
|
|
|
{
|
2017-12-20 12:45:01 +01:00
|
|
|
if (chain == CBaseChainParams::DEVNET) {
|
|
|
|
std::string devNetName = GetDevNetName();
|
|
|
|
assert(!devNetName.empty());
|
2018-10-25 09:17:37 +02:00
|
|
|
|
|
|
|
devNetParams = (CBaseDevNetParams*)new uint8_t[sizeof(CBaseDevNetParams)];
|
|
|
|
memset(devNetParams, 0, sizeof(CBaseDevNetParams));
|
|
|
|
new (devNetParams) CBaseDevNetParams(devNetName);
|
2017-12-20 12:45:01 +01:00
|
|
|
}
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
pCurrentBaseParams = &BaseParams(chain);
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 21:39:49 +02:00
|
|
|
std::string ChainNameFromCommandLine()
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
bool fRegTest = GetBoolArg("-regtest", false);
|
2018-01-16 07:17:45 +01:00
|
|
|
bool fDevNet = IsArgSet("-devnet");
|
2014-06-19 15:10:04 +02:00
|
|
|
bool fTestNet = GetBoolArg("-testnet", false);
|
|
|
|
|
2017-12-20 12:45:01 +01:00
|
|
|
int nameParamsCount = (fRegTest ? 1 : 0) + (fDevNet ? 1 : 0) + (fTestNet ? 1 : 0);
|
|
|
|
if (nameParamsCount > 1)
|
|
|
|
throw std::runtime_error("Only one of -regtest, -testnet or -devnet can be used.");
|
|
|
|
|
|
|
|
if (fDevNet)
|
|
|
|
return CBaseChainParams::DEVNET;
|
2014-09-01 00:41:28 +02:00
|
|
|
if (fRegTest)
|
2014-10-09 19:15:38 +02:00
|
|
|
return CBaseChainParams::REGTEST;
|
2014-09-01 00:41:28 +02:00
|
|
|
if (fTestNet)
|
2014-10-09 19:15:38 +02:00
|
|
|
return CBaseChainParams::TESTNET;
|
|
|
|
return CBaseChainParams::MAIN;
|
2014-09-01 00:41:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-20 12:45:01 +01:00
|
|
|
std::string GetDevNetName()
|
|
|
|
{
|
|
|
|
// This function should never be called for non-devnets
|
2018-01-16 07:17:45 +01:00
|
|
|
assert(IsArgSet("-devnet"));
|
2017-12-20 12:45:01 +01:00
|
|
|
std::string devNetName = GetArg("-devnet", "");
|
|
|
|
return "devnet" + (devNetName.empty() ? "" : "-" + devNetName);
|
|
|
|
}
|
|
|
|
|
2014-09-19 19:21:46 +02:00
|
|
|
bool AreBaseParamsConfigured()
|
|
|
|
{
|
2014-07-15 10:22:27 +02:00
|
|
|
return pCurrentBaseParams != NULL;
|
|
|
|
}
|