Dogecoin Core  1.14.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 
17 void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
18 {
19  strUsage += HelpMessageGroup(_("Chain selection options:"));
20  strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
21  if (debugHelp) {
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.");
24  }
25 }
26 
31 {
32 public:
34  {
35  nRPCPort = 22555;
36  }
37 };
38 static CBaseMainParams mainParams;
39 
44 {
45 public:
47  {
48  nRPCPort = 44555;
49  strDataDir = "testnet3";
50  }
51 };
52 static CBaseTestNetParams testNetParams;
53 
54 /*
55  * Regression test
56  */
58 {
59 public:
61  {
62  nRPCPort = 18332;
63  strDataDir = "regtest";
64  }
65 };
66 static CBaseRegTestParams regTestParams;
67 
68 static CBaseChainParams* pCurrentBaseParams = 0;
69 
71 {
72  assert(pCurrentBaseParams);
73  return *pCurrentBaseParams;
74 }
75 
76 CBaseChainParams& BaseParams(const std::string& chain)
77 {
78  if (chain == CBaseChainParams::MAIN)
79  return mainParams;
80  else if (chain == CBaseChainParams::TESTNET)
81  return testNetParams;
82  else if (chain == CBaseChainParams::REGTEST)
83  return regTestParams;
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  pCurrentBaseParams = &BaseParams(chain);
91 }
92 
94 {
95  bool fRegTest = GetBoolArg("-regtest", false);
96  bool fTestNet = 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 }
106 
108 {
109  return pCurrentBaseParams != NULL;
110 }
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
bool AreBaseParamsConfigured()
Return true if SelectBaseParamsFromCommandLine() has been called to select a network.
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp)
Append the help messages for the chainparams options to the parameter string.
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
std::string strDataDir
Main network.
#define strprintf
Definition: tinyformat.h:1047
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:411
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:448
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:452
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
Definition: util.h:62