Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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 #include <memory>
13 
14 const std::string CBaseChainParams::MAIN = "main";
15 const std::string CBaseChainParams::TESTNET = "test";
16 const std::string CBaseChainParams::DEVNET = "devnet";
17 const std::string CBaseChainParams::REGTEST = "regtest";
18 
19 void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
20 {
21  strUsage += HelpMessageGroup(_("Chain selection options:"));
22  strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
23  strUsage += HelpMessageOpt("-devnet=<name>", _("Use devnet chain with provided name"));
24  if (debugHelp) {
25  strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
26  "This is intended for regression testing tools and app development.");
27  }
28 }
29 
34 {
35 public:
37  {
38  nRPCPort = 9998;
39  }
40 };
41 
46 {
47 public:
49  {
50  nRPCPort = 19998;
51  strDataDir = "testnet3";
52  }
53 };
54 
59 {
60 public:
61  CBaseDevNetParams(const std::string &dataDir)
62  {
63  nRPCPort = 19798;
64  strDataDir = dataDir;
65  }
66 };
67 
68 /*
69  * Regression test
70  */
72 {
73 public:
75  {
76  nRPCPort = 19898;
77  strDataDir = "regtest";
78  }
79 };
80 
81 static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
82 
84 {
85  assert(globalChainBaseParams);
86  return *globalChainBaseParams;
87 }
88 
89 std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
90 {
91  if (chain == CBaseChainParams::MAIN)
92  return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
93  else if (chain == CBaseChainParams::TESTNET)
94  return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
95  else if (chain == CBaseChainParams::DEVNET) {
96  return std::unique_ptr<CBaseChainParams>(new CBaseDevNetParams(gArgs.GetDevNetName()));
97  } else if (chain == CBaseChainParams::REGTEST)
98  return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
99  else
100  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
101 }
102 
103 void SelectBaseParams(const std::string& chain)
104 {
106  gArgs.SelectConfigNetwork(chain);
107 }
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:884
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:1066
std::string strDataDir
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: util.cpp:725
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
Main network.
CBaseDevNetParams(const std::string &dataDir)
static const std::string DEVNET
std::string GetDevNetName() const
Looks for -devnet and returns either "devnet-<name>" or simply "devnet" if no name was specified...
Definition: util.cpp:1045
ArgsManager gArgs
Definition: util.cpp:108
CBaseChainParams defines the base parameters (shared between dash-cli and dashd) of a given instance ...
static std::unique_ptr< CBaseChainParams > globalChainBaseParams
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:880
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:92
Released under the MIT license