PIVX Core  5.6.99
P2P Digital Currency
chainparamsbase.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2016-2021 The PIVX 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/system.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 
28 static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
29 
31 {
32  assert(globalChainBaseParams);
33  return *globalChainBaseParams;
34 }
35 
36 std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
37 {
38  if (chain == CBaseChainParams::MAIN)
39  return std::make_unique<CBaseChainParams>("", 51473);
40  else if (chain == CBaseChainParams::TESTNET)
41  return std::make_unique<CBaseChainParams>("testnet5", 51475);
42  else if (chain == CBaseChainParams::REGTEST)
43  return std::make_unique<CBaseChainParams>("regtest", 51477);
44  else
45  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
46 }
47 
48 void SelectBaseParams(const std::string& chain)
49 {
50  globalChainBaseParams = CreateBaseChainParams(chain);
52 }
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
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.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: system.cpp:366
CBaseChainParams defines the base parameters (shared between pivx-cli and pivxd) of a given instance ...
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
Chain name strings.
ArgsManager gArgs
Definition: system.cpp:89
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: system.cpp:499
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: system.cpp:503
#define strprintf
Definition: tinyformat.h:1056