LCOV - code coverage report
Current view: top level - src - chainparams.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 23 26 88.5 %
Date: 2020-09-26 01:30:44 Functions: 29 32 90.6 %

          Line data    Source code
       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 <primitives/block.h>
      12             : #include <protocol.h>
      13             : 
      14             : #include <memory>
      15             : #include <vector>
      16             : 
      17             : struct SeedSpec6 {
      18             :     uint8_t addr[16];
      19             :     uint16_t port;
      20             : };
      21             : 
      22             : typedef std::map<int, uint256> MapCheckpoints;
      23             : 
      24       97769 : struct CCheckpointData {
      25             :     MapCheckpoints mapCheckpoints;
      26             : 
      27        1010 :     int GetHeight() const {
      28        1010 :         const auto& final_checkpoint = mapCheckpoints.rbegin();
      29        2020 :         return final_checkpoint->first /* height */;
      30        1010 :     }
      31             : };
      32             : 
      33             : /**
      34             :  * Holds various statistics on transactions within a chain. Used to estimate
      35             :  * verification progress during chain sync.
      36             :  *
      37             :  * See also: CChainParams::TxData, GuessVerificationProgress.
      38             :  */
      39             : struct ChainTxData {
      40             :     int64_t nTime;    //!< UNIX timestamp of last known number of transactions
      41             :     int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
      42             :     double dTxRate;   //!< estimated number of transactions per second after that timestamp
      43             : };
      44             : 
      45             : /**
      46             :  * CChainParams defines various tweakable parameters of a given instance of the
      47             :  * Bitcoin system. There are three: the main network on which people trade goods
      48             :  * and services, the public test network which gets reset from time to time and
      49             :  * a regression test mode which is intended for private networks only. It has
      50             :  * minimal difficulty to ensure that blocks can be found instantly.
      51             :  */
      52      226722 : class CChainParams
      53             : {
      54             : public:
      55             :     enum Base58Type {
      56             :         PUBKEY_ADDRESS,
      57             :         SCRIPT_ADDRESS,
      58             :         SECRET_KEY,
      59             :         EXT_PUBLIC_KEY,
      60             :         EXT_SECRET_KEY,
      61             : 
      62             :         MAX_BASE58_TYPES
      63             :     };
      64             : 
      65     6945626 :     const Consensus::Params& GetConsensus() const { return consensus; }
      66      279951 :     const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
      67        4940 :     int GetDefaultPort() const { return nDefaultPort; }
      68             : 
      69        1581 :     const CBlock& GenesisBlock() const { return genesis; }
      70             :     /** Default value for -checkmempool and -checkblockindex argument */
      71        5539 :     bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
      72             :     /** Policy: Filter transactions that do not match well-defined patterns */
      73        2002 :     bool RequireStandard() const { return fRequireStandard; }
      74             :     /** If this chain is exclusively used for testing */
      75        1196 :     bool IsTestChain() const { return m_is_test_chain; }
      76             :     /** If this chain allows time to be mocked */
      77         483 :     bool IsMockableChain() const { return m_is_mockable_chain; }
      78           6 :     uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
      79             :     /** Minimum free space (in GB) needed for data directory */
      80           0 :     uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
      81             :     /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
      82           0 :     uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
      83             :     /** Whether it is possible to mine blocks on demand (no retargeting) */
      84       21011 :     bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
      85             :     /** Return the network string */
      86         368 :     std::string NetworkIDString() const { return strNetworkID; }
      87             :     /** Return the list of hostnames to look up for DNS seeds */
      88           0 :     const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
      89      100058 :     const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
      90       59226 :     const std::string& Bech32HRP() const { return bech32_hrp; }
      91          63 :     const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
      92       69742 :     const CCheckpointData& Checkpoints() const { return checkpointData; }
      93      128050 :     const ChainTxData& TxData() const { return chainTxData; }
      94             : protected:
      95       22195 :     CChainParams() {}
      96             : 
      97             :     Consensus::Params consensus;
      98             :     CMessageHeader::MessageStartChars pchMessageStart;
      99             :     int nDefaultPort;
     100             :     uint64_t nPruneAfterHeight;
     101             :     uint64_t m_assumed_blockchain_size;
     102             :     uint64_t m_assumed_chain_state_size;
     103             :     std::vector<std::string> vSeeds;
     104             :     std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
     105             :     std::string bech32_hrp;
     106             :     std::string strNetworkID;
     107             :     CBlock genesis;
     108             :     std::vector<SeedSpec6> vFixedSeeds;
     109             :     bool fDefaultConsistencyChecks;
     110             :     bool fRequireStandard;
     111             :     bool m_is_test_chain;
     112             :     bool m_is_mockable_chain;
     113             :     CCheckpointData checkpointData;
     114             :     ChainTxData chainTxData;
     115             : };
     116             : 
     117             : /**
     118             :  * Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
     119             :  * @returns a CChainParams* of the chosen chain.
     120             :  * @throws a std::runtime_error if the chain is not supported.
     121             :  */
     122             : std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain);
     123             : 
     124             : /**
     125             :  * Return the currently selected parameters. This won't change after app
     126             :  * startup, except for unit tests.
     127             :  */
     128             : const CChainParams &Params();
     129             : 
     130             : /**
     131             :  * Sets the params returned by Params() to those for the given chain name.
     132             :  * @throws std::runtime_error when the chain is not supported.
     133             :  */
     134             : void SelectParams(const std::string& chain);
     135             : 
     136             : #endif // BITCOIN_CHAINPARAMS_H

Generated by: LCOV version 1.15