Bitcoin Core  22.99.0
P2P Digital Currency
chainparamsbase.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 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 
11 #include <assert.h>
12 
13 const std::string CBaseChainParams::MAIN = "main";
14 const std::string CBaseChainParams::TESTNET = "test";
15 const std::string CBaseChainParams::SIGNET = "signet";
16 const std::string CBaseChainParams::REGTEST = "regtest";
17 
19 {
20  argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
21  argsman.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  argsman.AddArg("-segwitheight=<n>", "Set the activation height of segwit. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
24  argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
25  argsman.AddArg("-vbparams=deployment:start:end[:min_activation_height]", "Use given start/end times and min_activation_height for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
26  argsman.AddArg("-signet", "Use the signet chain. Equivalent to -chain=signet. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
27  argsman.AddArg("-signetchallenge", "Blocks must satisfy the given script to be considered valid (only for signet networks; defaults to the global default signet test network challenge)", ArgsManager::ALLOW_STRING, OptionsCategory::CHAINPARAMS);
28  argsman.AddArg("-signetseednode", "Specify a seed node for the signet network, in the hostname[:port] format, e.g. sig.net:1234 (may be used multiple times to specify multiple seed nodes; defaults to the global default signet test network seed node(s))", ArgsManager::ALLOW_STRING, OptionsCategory::CHAINPARAMS);
29 }
30 
31 static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
32 
34 {
36  return *globalChainBaseParams;
37 }
38 
43 std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
44 {
45  if (chain == CBaseChainParams::MAIN) {
46  return std::make_unique<CBaseChainParams>("", 8332, 8334);
47  } else if (chain == CBaseChainParams::TESTNET) {
48  return std::make_unique<CBaseChainParams>("testnet3", 18332, 18334);
49  } else if (chain == CBaseChainParams::SIGNET) {
50  return std::make_unique<CBaseChainParams>("signet", 38332, 38334);
51  } else if (chain == CBaseChainParams::REGTEST) {
52  return std::make_unique<CBaseChainParams>("regtest", 18443, 18445);
53  }
54  throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
55 }
56 
57 void SelectBaseParams(const std::string& chain)
58 {
61 }
assert
assert(!tx.IsCoinBase())
chainparamsbase.h
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:166
SetupChainParamsBaseOptions
void SetupChainParamsBaseOptions(ArgsManager &argsman)
Set the arguments for chainparams.
Definition: chainparamsbase.cpp:18
CBaseChainParams::TESTNET
static const std::string TESTNET
Definition: chainparamsbase.h:23
SelectBaseParams
void SelectBaseParams(const std::string &chain)
Sets the params returned by Params() to those for the given network.
Definition: chainparamsbase.cpp:57
ArgsManager::DEBUG_ONLY
@ DEBUG_ONLY
Definition: system.h:167
CBaseChainParams
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
Definition: chainparamsbase.h:17
tinyformat.h
ArgsManager::ALLOW_STRING
@ ALLOW_STRING
Definition: system.h:165
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:640
CBaseChainParams::REGTEST
static const std::string REGTEST
Definition: chainparamsbase.h:25
CreateBaseChainParams
std::unique_ptr< CBaseChainParams > CreateBaseChainParams(const std::string &chain)
Port numbers for incoming Tor connections (8334, 18334, 38334, 18445) have been chosen arbitrarily to...
Definition: chainparamsbase.cpp:43
gArgs
ArgsManager gArgs
Definition: system.cpp:84
CBaseChainParams::MAIN
static const std::string MAIN
Chain name strings.
Definition: chainparamsbase.h:22
ArgsManager::SelectConfigNetwork
void SelectConfigNetwork(const std::string &network)
Select the network in use.
Definition: system.cpp:298
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
ArgsManager
Definition: system.h:158
BaseParams
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
Definition: chainparamsbase.cpp:33
globalChainBaseParams
static std::unique_ptr< CBaseChainParams > globalChainBaseParams
Definition: chainparamsbase.cpp:31
OptionsCategory::DEBUG_TEST
@ DEBUG_TEST
OptionsCategory::CHAINPARAMS
@ CHAINPARAMS
CBaseChainParams::SIGNET
static const std::string SIGNET
Definition: chainparamsbase.h:24