Fabcoin Core  0.16.2
P2P Digital Currency
chainparamsbase.cpp
Go to the documentation of this file.
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.
5 
6 #include <chainparamsbase.h>
7 
8 #include <tinyformat.h>
9 #include <util.h>
10 
11 #include <assert.h>
12 
13 const std::string CBaseChainParams::MAIN = "main";
14 const std::string CBaseChainParams::TESTNET = "test";
15 const std::string CBaseChainParams::REGTEST = "regtest";
16 const std::string CBaseChainParams::UNITTEST = "unittest";
17 
18 void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
19 {
20  strUsage += HelpMessageGroup(_("Chain selection options:"));
21  strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
22  if (debugHelp) {
23  strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
24  "This is intended for regression testing tools and app development.");
25  }
26 }
27 
32 {
33 public:
35  {
36  nRPCPort = 8667;
37  }
38 };
39 
44 {
45 public:
47  {
48  nRPCPort = 18667;
49  strDataDir = "testnet3";
50  }
51 };
52 
53 /*
54  * Regression test
55  */
57 {
58 public:
60  {
61  nRPCPort = 38667;
62  strDataDir = "regtest";
63  }
64 };
65 
66 static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
67 
69 {
70  assert(globalChainBaseParams);
71  return *globalChainBaseParams;
72 }
73 
74 std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
75 {
76  if (chain == CBaseChainParams::MAIN)
77  return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
78  else if (chain == CBaseChainParams::TESTNET)
79  return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
80  else if (chain == CBaseChainParams::REGTEST)
81  return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
82  else if (chain == CBaseChainParams::UNITTEST)
83  return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
84  else
85  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
86 }
87 
88 void SelectBaseParams(const std::string& chain)
89 {
90  globalChainBaseParams = CreateBaseChainParams(chain);
91 }
92 
94 {
95  bool fRegTest = gArgs.GetBoolArg("-regtest", false);
96  bool fTestNet = gArgs.GetBoolArg("-testnet", false);
97 
98  if (fTestNet && fRegTest)
99  throw std::runtime_error("Invalid combination of -regtest and -testnet.");
100  if (fRegTest)
102  if (fTestNet)
104  return CBaseChainParams::MAIN;
105 }
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: util.cpp:563
std::unique_ptr< CBaseChainParams > CreateBaseChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain.
void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp)
Append the help messages for the chainparams options to the parameter string.
static const std::string REGTEST
#define strprintf
Definition: tinyformat.h:1054
std::string strDataDir
static const std::string UNITTEST
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:520
assert(len-trim+(2 *lenIndices)<=WIDTH)
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
Main network.
ArgsManager gArgs
Definition: util.cpp:94
CBaseChainParams defines the base parameters (shared between fabcoin-cli and fabcoind) of a given ins...
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
static const std::string TESTNET
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:559
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:71