Bitcoin Core 32.99.0
P2P Digital Currency
chainparamsbase.cpp
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-present 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 <common/args.h>
9#include <crypto/hex_base.h>
10#include <kernel/signet.h>
11#include <tinyformat.h>
12#include <util/chaintype.h>
13#include <util/strencodings.h>
14
15#include <cassert>
16
18{
19 argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: " LIST_CHAIN_NAMES, ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
20 argsman.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. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
22 argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (segwit, bip34, dersig, cltv, csv). (test-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
23 argsman.AddArg("-testnet", "Use the testnet3 chain. Equivalent to -chain=test. Support for testnet3 is deprecated and will be removed in an upcoming release. Consider moving to testnet4 now by using -testnet4.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
24 argsman.AddArg("-testnet4", "Use the testnet4 chain. Equivalent to -chain=testnet4.", 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 (test-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_ANY | ArgsManager::DISALLOW_NEGATION, 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_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::CHAINPARAMS);
29}
30
31static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
32
34{
37}
38
40{
41 std::string base_data_dir = "signet";
42 // no default to treat no -signetchallenge (default signet) as distinct from
43 // the empty -signetchallenge= (custom signet)
44 const auto challenge_hex = args.GetArg("-signetchallenge");
45 if (!challenge_hex) {
46 return base_data_dir;
47 }
48 // -signetchallenge can be invalid hex here (it's checked later in
49 // ReadSigNetArgs), but we don't mind to keep validation in one place.
50 const auto challenge_bytes = TryParseHex<uint8_t>(*challenge_hex);
51 if (!challenge_bytes || *challenge_bytes == kernel::SIGNET_DEFAULT_CHALLENGE) {
52 return base_data_dir;
53 }
54 return base_data_dir + "_" + HexStr(kernel::GetSignetMessageStart(*challenge_bytes));
55}
56
61std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ArgsManager& args, const ChainType chain)
62{
63 switch (chain) {
64 case ChainType::MAIN:
65 return std::make_unique<CBaseChainParams>("", 8332);
67 return std::make_unique<CBaseChainParams>("testnet3", 18332);
69 return std::make_unique<CBaseChainParams>("testnet4", 48332);
71 return std::make_unique<CBaseChainParams>(GetSignetDataDir(args), 38332);
73 return std::make_unique<CBaseChainParams>("regtest", 18443);
74 }
75 assert(false);
76}
77
78void SelectBaseParams(const ChainType chain)
79{
82}
ArgsManager gArgs
Definition: args.cpp:38
ArgsManager & args
Definition: bitcoind.cpp:280
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
static std::unique_ptr< CBaseChainParams > globalChainBaseParams
void SetupChainParamsBaseOptions(ArgsManager &argsman)
Set the arguments for chainparams.
void SelectBaseParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain.
std::unique_ptr< CBaseChainParams > CreateBaseChainParams(const ArgsManager &args, const ChainType chain)
Port numbers for incoming Tor connections (8334, 18334, 38334, 48334, 18445) have been chosen arbitra...
std::string GetSignetDataDir(const ArgsManager &args)
#define LIST_CHAIN_NAMES
List of possible chain / network names
std::string ChainTypeToString(ChainType chain)
Definition: chaintype.cpp:12
ChainType
Definition: chaintype.h:12
@ ALLOW_ANY
disable validation
Definition: args.h:114
@ DISALLOW_NEGATION
disallow -nofoo syntax
Definition: args.h:119
@ DEBUG_ONLY
Definition: args.h:122
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Add argument.
Definition: args.cpp:657
std::string GetArg(const std::string &strArg, const std::string &strDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return string argument or default value.
Definition: args.cpp:517
void SelectConfigNetwork(const std::string &network) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Select the network in use.
Definition: args.cpp:169
CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind) of a given ins...
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: hex_base.cpp:30
MessageStartChars GetSignetMessageStart(const std::vector< uint8_t > &signet_challenge)
Return the message start bytes for a signet: the first four bytes of the double-SHA256 hash of the se...
Definition: signet.h:27
const std::vector< uint8_t > SIGNET_DEFAULT_CHALLENGE
Definition: signet.h:20
assert(!tx.IsCoinBase())