1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "chainparamsbase.h"
8 #include "tinyformat.h"
13 const std::string
CBaseChainParams::MAIN
= "main";
14 const std::string
CBaseChainParams::TESTNET
= "test";
15 const std::string
CBaseChainParams::REGTEST
= "regtest";
17 void AppendParamsHelpMessages(std::string
& strUsage
, bool debugHelp
)
19 strUsage
+= HelpMessageGroup(_("Chain selection options:"));
20 strUsage
+= HelpMessageOpt("-testnet", _("Use the test chain"));
22 strUsage
+= HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
23 "This is intended for regression testing tools and app development.");
30 class CBaseMainParams
: public CBaseChainParams
42 class CBaseTestNetParams
: public CBaseChainParams
48 strDataDir
= "testnet3";
55 class CBaseRegTestParams
: public CBaseChainParams
61 strDataDir
= "regtest";
65 static std::unique_ptr
<CBaseChainParams
> globalChainBaseParams
;
67 const CBaseChainParams
& BaseParams()
69 assert(globalChainBaseParams
);
70 return *globalChainBaseParams
;
73 std::unique_ptr
<CBaseChainParams
> CreateBaseChainParams(const std::string
& chain
)
75 if (chain
== CBaseChainParams::MAIN
)
76 return std::unique_ptr
<CBaseChainParams
>(new CBaseMainParams());
77 else if (chain
== CBaseChainParams::TESTNET
)
78 return std::unique_ptr
<CBaseChainParams
>(new CBaseTestNetParams());
79 else if (chain
== CBaseChainParams::REGTEST
)
80 return std::unique_ptr
<CBaseChainParams
>(new CBaseRegTestParams());
82 throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__
, chain
));
85 void SelectBaseParams(const std::string
& chain
)
87 globalChainBaseParams
= CreateBaseChainParams(chain
);
90 std::string
ChainNameFromCommandLine()
92 bool fRegTest
= gArgs
.GetBoolArg("-regtest", false);
93 bool fTestNet
= gArgs
.GetBoolArg("-testnet", false);
95 if (fTestNet
&& fRegTest
)
96 throw std::runtime_error("Invalid combination of -regtest and -testnet.");
98 return CBaseChainParams::REGTEST
;
100 return CBaseChainParams::TESTNET
;
101 return CBaseChainParams::MAIN
;