Bitcoin Core  0.18.99
P2P Digital Currency
chainparamsbase.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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/system.h>
10 #include <util/memory.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 
19 {
20  gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
21  "This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
22  gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
23  gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", true, OptionsCategory::CHAINPARAMS);
24 }
25 
26 static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
27 
29 {
30  assert(globalChainBaseParams);
31  return *globalChainBaseParams;
32 }
33 
34 std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
35 {
36  if (chain == CBaseChainParams::MAIN)
37  return MakeUnique<CBaseChainParams>("", 8332);
38  else if (chain == CBaseChainParams::TESTNET)
39  return MakeUnique<CBaseChainParams>("testnet3", 18332);
40  else if (chain == CBaseChainParams::REGTEST)
41  return MakeUnique<CBaseChainParams>("regtest", 18443);
42  else
43  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
44 }
45 
46 void SelectBaseParams(const std::string& chain)
47 {
48  globalChainBaseParams = CreateBaseChainParams(chain);
50 }
std::unique_ptr< CBaseChainParams > CreateBaseChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CBaseChainParams> of the chosen chain.
static const std::string REGTEST
#define strprintf
Definition: tinyformat.h:1066
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: system.cpp:375
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
void SetupChainParamsBaseOptions()
Set the arguments for chainparams.
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:542
ArgsManager gArgs
Definition: system.cpp:74
static const std::string TESTNET
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.