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("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
21  gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
22  "This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
23  gArgs.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
24  gArgs.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
25  gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
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 MakeUnique<CBaseChainParams>("", 8332);
40  else if (chain == CBaseChainParams::TESTNET)
41  return MakeUnique<CBaseChainParams>("testnet3", 18332);
42  else if (chain == CBaseChainParams::REGTEST)
43  return MakeUnique<CBaseChainParams>("regtest", 18443);
44  else
45  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
46 }
47 
48 void SelectBaseParams(const std::string& chain)
49 {
52 }
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
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1067
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: system.cpp:370
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:542
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
void SetupChainParamsBaseOptions()
Set the arguments for chainparams.
ArgsManager gArgs
Definition: system.cpp:73
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.