Bitcoin Core  22.99.0
P2P Digital Currency
chainparams.h
Go to the documentation of this file.
1 // Copyright (c) 2009-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 #ifndef BITCOIN_CHAINPARAMS_H
7 #define BITCOIN_CHAINPARAMS_H
8 
9 #include <chainparamsbase.h>
10 #include <consensus/params.h>
11 #include <netaddress.h>
12 #include <primitives/block.h>
13 #include <protocol.h>
14 #include <util/hash_type.h>
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 typedef std::map<int, uint256> MapCheckpoints;
21 
24 
25  int GetHeight() const {
26  const auto& final_checkpoint = mapCheckpoints.rbegin();
27  return final_checkpoint->first /* height */;
28  }
29 };
30 
31 struct AssumeutxoHash : public BaseHash<uint256> {
32  explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
33 };
34 
43 
48  const unsigned int nChainTx;
49 };
50 
51 using MapAssumeutxo = std::map<int, const AssumeutxoData>;
52 
59 struct ChainTxData {
60  int64_t nTime;
61  int64_t nTxCount;
62  double dTxRate;
63 };
64 
70 {
71 public:
72  enum Base58Type {
78 
80  };
81 
82  const Consensus::Params& GetConsensus() const { return consensus; }
84  uint16_t GetDefaultPort() const { return nDefaultPort; }
85  uint16_t GetDefaultPort(Network net) const
86  {
87  return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
88  }
89  uint16_t GetDefaultPort(const std::string& addr) const
90  {
91  CNetAddr a;
92  return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort();
93  }
94 
95  const CBlock& GenesisBlock() const { return genesis; }
99  bool RequireStandard() const { return fRequireStandard; }
101  bool IsTestChain() const { return m_is_test_chain; }
103  bool IsMockableChain() const { return m_is_mockable_chain; }
104  uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
112  std::string NetworkIDString() const { return strNetworkID; }
114  const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
115  const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
116  const std::string& Bech32HRP() const { return bech32_hrp; }
117  const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
118  const CCheckpointData& Checkpoints() const { return checkpointData; }
119 
122  const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
123 
124  const ChainTxData& TxData() const { return chainTxData; }
125 protected:
127 
130  uint16_t nDefaultPort;
134  std::vector<std::string> vSeeds;
135  std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
136  std::string bech32_hrp;
137  std::string strNetworkID;
139  std::vector<uint8_t> vFixedSeeds;
147 };
148 
154 std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const std::string& chain);
155 
160 const CChainParams &Params();
161 
166 void SelectParams(const std::string& chain);
167 
168 #endif // BITCOIN_CHAINPARAMS_H
CChainParams::m_assumed_blockchain_size
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:132
CreateChainParams
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Definition: chainparams.cpp:566
block.h
I2P_SAM31_PORT
static constexpr uint16_t I2P_SAM31_PORT
SAM 3.1 and earlier do not support specifying ports and force the port to 0.
Definition: netaddress.h:113
CChainParams::IsMockableChain
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:103
CChainParams::EXT_PUBLIC_KEY
@ EXT_PUBLIC_KEY
Definition: chainparams.h:76
AssumeutxoHash
Definition: chainparams.h:31
CChainParams::strNetworkID
std::string strNetworkID
Definition: chainparams.h:137
CChainParams::chainTxData
ChainTxData chainTxData
Definition: chainparams.h:146
CChainParams::m_assumed_chain_state_size
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:133
CChainParams::CChainParams
CChainParams()
Definition: chainparams.h:126
AssumeutxoData
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:40
CChainParams::IsTestChain
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:101
CChainParams::fRequireStandard
bool fRequireStandard
Definition: chainparams.h:141
CNetAddr
Network address.
Definition: netaddress.h:118
chainparamsbase.h
hash_type.h
CChainParams::bech32_hrp
std::string bech32_hrp
Definition: chainparams.h:136
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
CChainParams::vSeeds
std::vector< std::string > vSeeds
Definition: chainparams.h:134
CChainParams::m_is_test_chain
bool m_is_test_chain
Definition: chainparams.h:142
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
CCheckpointData::mapCheckpoints
MapCheckpoints mapCheckpoints
Definition: chainparams.h:23
CChainParams::pchMessageStart
CMessageHeader::MessageStartChars pchMessageStart
Definition: chainparams.h:129
BaseHash
Definition: hash_type.h:9
Network
Network
A network type.
Definition: netaddress.h:45
ChainTxData::nTime
int64_t nTime
UNIX timestamp of last known number of transactions.
Definition: chainparams.h:60
CChainParams::fDefaultConsistencyChecks
bool fDefaultConsistencyChecks
Definition: chainparams.h:140
CChainParams::MAX_BASE58_TYPES
@ MAX_BASE58_TYPES
Definition: chainparams.h:79
CChainParams::m_is_mockable_chain
bool m_is_mockable_chain
Definition: chainparams.h:143
CChainParams::PruneAfterHeight
uint64_t PruneAfterHeight() const
Definition: chainparams.h:104
CChainParams::FixedSeeds
const std::vector< uint8_t > & FixedSeeds() const
Definition: chainparams.h:117
CChainParams::genesis
CBlock genesis
Definition: chainparams.h:138
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:70
NET_I2P
@ NET_I2P
I2P.
Definition: netaddress.h:59
protocol.h
CNetAddr::GetNetwork
enum Network GetNetwork() const
Definition: netaddress.cpp:524
CChainParams::nDefaultPort
uint16_t nDefaultPort
Definition: chainparams.h:130
SelectParams
void SelectParams(const std::string &chain)
Sets the params returned by Params() to those for the given chain name.
Definition: chainparams.cpp:580
CNetAddr::SetSpecial
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
CChainParams::SECRET_KEY
@ SECRET_KEY
Definition: chainparams.h:75
CChainParams::GetDefaultPort
uint16_t GetDefaultPort(Network net) const
Definition: chainparams.h:85
CChainParams::AssumedBlockchainSize
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:106
netaddress.h
ChainTxData::nTxCount
int64_t nTxCount
total number of transactions between genesis and that timestamp
Definition: chainparams.h:61
ChainTxData
Holds various statistics on transactions within a chain.
Definition: chainparams.h:59
CChainParams::Base58Prefix
const std::vector< unsigned char > & Base58Prefix(Base58Type type) const
Definition: chainparams.h:115
CChainParams::NetworkIDString
std::string NetworkIDString() const
Return the network string.
Definition: chainparams.h:112
CCheckpointData
Definition: chainparams.h:22
MapCheckpoints
std::map< int, uint256 > MapCheckpoints
Definition: chainparams.h:20
CChainParams::GenesisBlock
const CBlock & GenesisBlock() const
Definition: chainparams.h:95
uint256
256-bit opaque blob.
Definition: uint256.h:124
CChainParams::checkpointData
CCheckpointData checkpointData
Definition: chainparams.h:144
CChainParams::Base58Type
Base58Type
Definition: chainparams.h:72
ChainTxData::dTxRate
double dTxRate
estimated number of transactions per second after that timestamp
Definition: chainparams.h:62
CChainParams::MessageStart
const CMessageHeader::MessageStartChars & MessageStart() const
Definition: chainparams.h:83
CChainParams::AssumedChainStateSize
uint64_t AssumedChainStateSize() const
Minimum free space (in GB) needed for data directory when pruned; Does not include prune target.
Definition: chainparams.h:108
CChainParams::DNSSeeds
const std::vector< std::string > & DNSSeeds() const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:114
Consensus::Params::fPowNoRetargeting
bool fPowNoRetargeting
Definition: params.h:102
CCheckpointData::GetHeight
int GetHeight() const
Definition: chainparams.h:25
CChainParams::base58Prefixes
std::vector< unsigned char > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:135
CBlock
Definition: block.h:62
CChainParams::EXT_SECRET_KEY
@ EXT_SECRET_KEY
Definition: chainparams.h:77
ArgsManager
Definition: system.h:158
AssumeutxoData::hash_serialized
const AssumeutxoHash hash_serialized
The expected hash of the deserialized UTXO set.
Definition: chainparams.h:42
CChainParams::Checkpoints
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:118
CChainParams::RequireStandard
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:99
params.h
CChainParams::TxData
const ChainTxData & TxData() const
Definition: chainparams.h:124
CMessageHeader::MessageStartChars
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:40
CChainParams::PUBKEY_ADDRESS
@ PUBKEY_ADDRESS
Definition: chainparams.h:73
CChainParams::vFixedSeeds
std::vector< uint8_t > vFixedSeeds
Definition: chainparams.h:139
CChainParams::MineBlocksOnDemand
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:110
AssumeutxoData::nChainTx
const unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
Definition: chainparams.h:48
CChainParams::consensus
Consensus::Params consensus
Definition: chainparams.h:128
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:561
CChainParams::Assumeutxo
const MapAssumeutxo & Assumeutxo() const
Get allowed assumeutxo configuration.
Definition: chainparams.h:122
CChainParams::Bech32HRP
const std::string & Bech32HRP() const
Definition: chainparams.h:116
CChainParams::GetDefaultPort
uint16_t GetDefaultPort(const std::string &addr) const
Definition: chainparams.h:89
CChainParams::nPruneAfterHeight
uint64_t nPruneAfterHeight
Definition: chainparams.h:131
AssumeutxoHash::AssumeutxoHash
AssumeutxoHash(const uint256 &hash)
Definition: chainparams.h:32
CChainParams::SCRIPT_ADDRESS
@ SCRIPT_ADDRESS
Definition: chainparams.h:74
MapAssumeutxo
std::map< int, const AssumeutxoData > MapAssumeutxo
Definition: chainparams.h:51
CChainParams::m_assumeutxo_data
MapAssumeutxo m_assumeutxo_data
Definition: chainparams.h:145
CChainParams::DefaultConsistencyChecks
bool DefaultConsistencyChecks() const
Default value for -checkmempool and -checkblockindex argument.
Definition: chainparams.h:97
CChainParams::GetDefaultPort
uint16_t GetDefaultPort() const
Definition: chainparams.h:84