Raven Core  3.0.0
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 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "chainparamsbase.h"
8 
9 #include "tinyformat.h"
10 #include "util.h"
11 
12 #include <assert.h>
13 
14 const std::string CBaseChainParams::MAIN = "main";
15 const std::string CBaseChainParams::TESTNET = "test";
16 const std::string CBaseChainParams::REGTEST = "regtest";
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 = 8766;
37  }
38 };
39 
44 {
45 public:
47  {
48  nRPCPort = 18766;
49  strDataDir = "testnet6";
50  }
51 };
52 
53 /*
54  * Regression test
55  */
57 {
58 public:
60  {
61  nRPCPort = 18443;
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
83  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
84 }
85 
86 void SelectBaseParams(const std::string& chain)
87 {
88  globalChainBaseParams = CreateBaseChainParams(chain);
89 }
90 
92 {
93  bool fRegTest = gArgs.GetBoolArg("-regtest", false);
94  bool fTestNet = gArgs.GetBoolArg("-testnet", false);
95 
96  if (fTestNet && fRegTest)
97  throw std::runtime_error("Invalid combination of -regtest and -testnet.");
98  if (fRegTest)
100  if (fTestNet)
102  return CBaseChainParams::MAIN;
103 }
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:511
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
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:470
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 raven-cli and ravend) of a given instanc...
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:506
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:66