Bitcoin ABC  0.26.3
P2P Digital Currency
chainparams.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 struct SeedSpec6 {
21  uint8_t addr[16];
22  uint16_t port;
23 };
24 
25 typedef std::map<int, BlockHash> MapCheckpoints;
26 
29 };
30 
31 struct AssumeutxoHash : public BaseHash<uint256> {
32  explicit AssumeutxoHash(const uint256 &hash) : BaseHash(hash) {}
33 };
34 
43 
50  const unsigned int nChainTx;
51 };
52 
53 using MapAssumeutxo = std::map<int, const AssumeutxoData>;
54 
61 struct ChainTxData {
62  int64_t nTime;
63  int64_t nTxCount;
64  double dTxRate;
65 };
66 
74 class CChainParams {
75 public:
76  enum Base58Type {
82 
84  };
85 
86  const Consensus::Params &GetConsensus() const { return consensus; }
88  const CMessageHeader::MessageMagic &NetMagic() const { return netMagic; }
89  uint16_t GetDefaultPort() const { return nDefaultPort; }
90  uint16_t GetDefaultPort(Network net) const {
91  return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort();
92  }
93  uint16_t GetDefaultPort(const std::string &addr) const {
94  CNetAddr a;
95  return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork())
96  : GetDefaultPort();
97  }
98 
99  const CBlock &GenesisBlock() const { return genesis; }
103  bool RequireStandard() const { return fRequireStandard; }
105  bool IsTestChain() const { return m_is_test_chain; }
107  bool IsMockableChain() const { return m_is_mockable_chain; }
108  uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
115  uint64_t AssumedChainStateSize() const {
117  }
121  std::string NetworkIDString() const { return strNetworkID; }
123  const std::vector<uint8_t> &Base58Prefix(Base58Type type) const {
124  return base58Prefixes[type];
125  }
126  const std::string &CashAddrPrefix() const { return cashaddrPrefix; }
127  const std::vector<SeedSpec6> &FixedSeeds() const { return vFixedSeeds; }
128  const CCheckpointData &Checkpoints() const { return checkpointData; }
129 
132  const MapAssumeutxo &Assumeutxo() const { return m_assumeutxo_data; }
133 
134  const ChainTxData &TxData() const { return chainTxData; }
135 
136 protected:
138 
142  uint16_t nDefaultPort;
146  std::vector<std::string> vSeeds;
147  std::vector<uint8_t> base58Prefixes[MAX_BASE58_TYPES];
148  std::string cashaddrPrefix;
149  std::string strNetworkID;
151  std::vector<SeedSpec6> vFixedSeeds;
159 
160  friend const std::vector<std::string>
161  GetRandomizedDNSSeeds(const CChainParams &params);
162 };
163 
169 std::unique_ptr<CChainParams> CreateChainParams(const std::string &chain);
170 
171 CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits,
172  int32_t nVersion, const Amount genesisReward);
173 
178 const CChainParams &Params();
179 
184 void SelectParams(const std::string &chain);
185 
186 const CCheckpointData &CheckpointData(const std::string &chain);
187 
188 #endif // BITCOIN_CHAINPARAMS_H
CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const Amount genesisReward)
Build the genesis block.
Definition: chainparams.cpp:59
std::map< int, const AssumeutxoData > MapAssumeutxo
Definition: chainparams.h:53
std::map< int, BlockHash > MapCheckpoints
Definition: chainparams.h:25
const CCheckpointData & CheckpointData(const std::string &chain)
void SelectParams(const std::string &chain)
Sets the params returned by Params() to those for the given BIP70 chain name.
const CChainParams & Params()
Return the currently selected parameters.
std::unique_ptr< CChainParams > CreateChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Definition: block.h:55
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
uint64_t m_assumed_chain_state_size
Definition: chainparams.h:145
const std::vector< uint8_t > & Base58Prefix(Base58Type type) const
Return the list of hostnames to look up for DNS seeds.
Definition: chainparams.h:123
bool DefaultConsistencyChecks() const
Default value for -checkmempool and -checkblockindex argument.
Definition: chainparams.h:101
bool m_is_test_chain
Definition: chainparams.h:154
std::string NetworkIDString() const
Return the BIP70 network string (main, test or regtest)
Definition: chainparams.h:121
CBlock genesis
Definition: chainparams.h:150
uint16_t GetDefaultPort(const std::string &addr) const
Definition: chainparams.h:93
bool RequireStandard() const
Policy: Filter transactions that do not match well-defined patterns.
Definition: chainparams.h:103
MapAssumeutxo m_assumeutxo_data
Definition: chainparams.h:157
const ChainTxData & TxData() const
Definition: chainparams.h:134
uint64_t m_assumed_blockchain_size
Definition: chainparams.h:144
const CCheckpointData & Checkpoints() const
Definition: chainparams.h:128
const CMessageHeader::MessageMagic & NetMagic() const
Definition: chainparams.h:88
bool IsMockableChain() const
If this chain allows time to be mocked.
Definition: chainparams.h:107
CMessageHeader::MessageMagic netMagic
Definition: chainparams.h:141
std::vector< uint8_t > base58Prefixes[MAX_BASE58_TYPES]
Definition: chainparams.h:147
bool fDefaultConsistencyChecks
Definition: chainparams.h:152
std::vector< SeedSpec6 > vFixedSeeds
Definition: chainparams.h:151
std::string strNetworkID
Definition: chainparams.h:149
const MapAssumeutxo & Assumeutxo() const
Get allowed assumeutxo configuration.
Definition: chainparams.h:132
bool IsTestChain() const
If this chain is exclusively used for testing.
Definition: chainparams.h:105
bool MineBlocksOnDemand() const
Whether it is possible to mine blocks on demand (no retargeting)
Definition: chainparams.h:119
const CMessageHeader::MessageMagic & DiskMagic() const
Definition: chainparams.h:87
Consensus::Params consensus
Definition: chainparams.h:139
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:86
const std::string & CashAddrPrefix() const
Definition: chainparams.h:126
friend const std::vector< std::string > GetRandomizedDNSSeeds(const CChainParams &params)
Return the list of hostnames to look up for DNS seeds.
Definition: dnsseeds.cpp:11
uint16_t GetDefaultPort() const
Definition: chainparams.h:89
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
Definition: chainparams.h:110
bool fRequireStandard
Definition: chainparams.h:153
std::string cashaddrPrefix
Definition: chainparams.h:148
std::vector< std::string > vSeeds
Definition: chainparams.h:146
bool m_is_mockable_chain
Definition: chainparams.h:155
CMessageHeader::MessageMagic diskMagic
Definition: chainparams.h:140
uint64_t AssumedChainStateSize() const
Minimum free space (in GB) needed for data directory when pruned; Does not include prune target.
Definition: chainparams.h:115
uint64_t PruneAfterHeight() const
Definition: chainparams.h:108
CCheckpointData checkpointData
Definition: chainparams.h:156
uint16_t nDefaultPort
Definition: chainparams.h:142
const std::vector< SeedSpec6 > & FixedSeeds() const
Definition: chainparams.h:127
const CBlock & GenesisBlock() const
Definition: chainparams.h:99
uint64_t nPruneAfterHeight
Definition: chainparams.h:143
ChainTxData chainTxData
Definition: chainparams.h:158
uint16_t GetDefaultPort(Network net) const
Definition: chainparams.h:90
std::array< uint8_t, MESSAGE_START_SIZE > MessageMagic
Definition: protocol.h:49
Network address.
Definition: netaddress.h:122
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:227
enum Network GetNetwork() const
Definition: netaddress.cpp:551
256-bit opaque blob.
Definition: uint256.h:127
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:117
Network
A network type.
Definition: netaddress.h:45
@ NET_I2P
I2P.
Definition: netaddress.h:60
Definition: amount.h:19
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:40
const AssumeutxoHash hash_serialized
The expected hash of the deserialized UTXO set.
Definition: chainparams.h:42
const unsigned int nChainTx
Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
Definition: chainparams.h:50
AssumeutxoHash(const uint256 &hash)
Definition: chainparams.h:32
MapCheckpoints mapCheckpoints
Definition: chainparams.h:28
Holds various statistics on transactions within a chain.
Definition: chainparams.h:61
double dTxRate
Definition: chainparams.h:64
int64_t nTime
Definition: chainparams.h:62
int64_t nTxCount
Definition: chainparams.h:63
Parameters that influence chain consensus.
Definition: params.h:76
bool fPowNoRetargeting
Definition: params.h:123
uint16_t port
Definition: chainparams.h:22
uint8_t addr[16]
Definition: chainparams.h:21