2014-06-19 15:10:04 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-10-25 17:24:16 +08: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-11-17 02:38:31 +01:00
|
|
|
const std::string CBaseChainParams::MAIN = CHAINPARAMS_OLD_MAIN;
|
|
|
|
|
const std::string CBaseChainParams::REGTEST = CHAINPARAMS_REGTEST;
|
2016-10-21 19:15:26 +02:00
|
|
|
const std::string CBaseChainParams::CUSTOM = "custom";
|
2015-05-25 09:00:17 +02:00
|
|
|
|
|
|
|
|
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
|
|
|
|
|
{
|
|
|
|
|
strUsage += HelpMessageGroup(_("Chain selection options:"));
|
2015-11-17 02:38:31 +01:00
|
|
|
strUsage += HelpMessageOpt("-chain=<chain>", strprintf(_("Use the chain <chain> (default: %s). Allowed values: main, testnet, regtest, custom"), CHAINPARAMS_ELEMENTS));
|
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.");
|
2016-10-21 19:15:26 +02:00
|
|
|
strUsage += HelpMessageGroup(_("Custom chain selection options (only for -chain=custom):"));
|
|
|
|
|
strUsage += HelpMessageOpt("-chainpetname=<name>", _("Alternative name for custom chain (default: custom). This changes the genesis block."));
|
2015-05-25 09:00:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-30 21:39:49 +02:00
|
|
|
|
2014-10-25 17:24:16 +08:00
|
|
|
/**
|
2015-11-17 02:38:31 +01:00
|
|
|
* Old Main network
|
2014-10-25 17:24:16 +08:00
|
|
|
*/
|
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()
|
|
|
|
|
{
|
2014-06-19 15:10:04 +02:00
|
|
|
nRPCPort = 8332;
|
2015-11-17 02:38:31 +01:00
|
|
|
strDataDir = CHAINPARAMS_OLD_MAIN;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Main network for elements
|
|
|
|
|
*/
|
|
|
|
|
class CBaseElementsParams : public CBaseChainParams
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CBaseElementsParams()
|
|
|
|
|
{
|
|
|
|
|
nRPCPort = 4241;
|
|
|
|
|
strDataDir = CHAINPARAMS_ELEMENTS;
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-25 17:24:16 +08: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;
|
2015-11-17 02:38:31 +01:00
|
|
|
strDataDir = CHAINPARAMS_REGTEST;
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-21 19:15:26 +02:00
|
|
|
/** Custom tests */
|
|
|
|
|
class CBaseCustomParams : public CBaseChainParams
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CBaseCustomParams()
|
|
|
|
|
{
|
|
|
|
|
nRPCPort = 18332;
|
|
|
|
|
strDataDir = "custom";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-22 03:50:01 +02:00
|
|
|
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2014-09-19 19:21:46 +02:00
|
|
|
const CBaseChainParams& BaseParams()
|
|
|
|
|
{
|
2015-05-22 03:50:01 +02:00
|
|
|
assert(globalChainBaseParams);
|
|
|
|
|
return *globalChainBaseParams;
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-22 03:50:01 +02:00
|
|
|
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(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-05-22 03:50:01 +02:00
|
|
|
return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
|
2015-11-17 02:38:31 +01:00
|
|
|
else if (chain == CHAINPARAMS_ELEMENTS)
|
|
|
|
|
return std::unique_ptr<CBaseChainParams>(new CBaseElementsParams());
|
2015-06-30 21:39:49 +02:00
|
|
|
else if (chain == CBaseChainParams::REGTEST)
|
2015-05-22 03:50:01 +02:00
|
|
|
return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
|
2016-10-21 19:15:26 +02:00
|
|
|
else if (chain == CBaseChainParams::CUSTOM)
|
|
|
|
|
return std::unique_ptr<CBaseChainParams>(new CBaseCustomParams());
|
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 19:21:41 +00:00
|
|
|
void SelectBaseParams(const std::string& chain)
|
|
|
|
|
{
|
2015-05-22 03:50:01 +02:00
|
|
|
globalChainBaseParams = CreateBaseChainParams(chain);
|
2015-06-27 19:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-30 21:39:49 +02:00
|
|
|
std::string ChainNameFromCommandLine()
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2015-11-16 14:01:22 +01:00
|
|
|
if (GetBoolArg("-testnet", false))
|
2015-11-17 02:38:31 +01:00
|
|
|
throw std::runtime_error(strprintf("%s: Invalid option -testnet: elements/%s is a testchain too.", __func__, CHAINPARAMS_ELEMENTS));
|
2015-11-16 14:01:22 +01:00
|
|
|
if (GetBoolArg("-regtest", false))
|
2014-10-09 19:15:38 +02:00
|
|
|
return CBaseChainParams::REGTEST;
|
2015-11-17 02:38:31 +01:00
|
|
|
return GetArg("-chain", CHAINPARAMS_ELEMENTS);
|
2014-09-01 00:41:28 +02:00
|
|
|
}
|