You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chainparams.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2015 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. #ifndef BITCOIN_CHAINPARAMS_H
  6. #define BITCOIN_CHAINPARAMS_H
  7. #include "chainparamsbase.h"
  8. #include "consensus/params.h"
  9. #include "primitives/block.h"
  10. #include "protocol.h"
  11. #include <vector>
  12. class CDNSSeedData {
  13. public:
  14. std::string name, host;
  15. bool supportsServiceBitsFiltering;
  16. std::string getHost(uint64_t requiredServiceBits) const;
  17. CDNSSeedData(const std::string &strName, const std::string &strHost, bool supportsServiceBitsFilteringIn = false) : name(strName), host(strHost), supportsServiceBitsFiltering(supportsServiceBitsFilteringIn) {}
  18. };
  19. struct SeedSpec6 {
  20. uint8_t addr[16];
  21. uint16_t port;
  22. };
  23. typedef std::map<int, uint256> MapCheckpoints;
  24. struct CCheckpointData {
  25. MapCheckpoints mapCheckpoints;
  26. int64_t nTimeLastCheckpoint;
  27. int64_t nTransactionsLastCheckpoint;
  28. double fTransactionsPerDay;
  29. };
  30. /**
  31. * CChainParams defines various tweakable parameters of a given instance of the
  32. * Bitcoin system. There are three: the main network on which people trade goods
  33. * and services, the public test network which gets reset from time to time and
  34. * a regression test mode which is intended for private networks only. It has
  35. * minimal difficulty to ensure that blocks can be found instantly.
  36. */
  37. class CChainParams
  38. {
  39. public:
  40. enum Base58Type {
  41. PUBKEY_ADDRESS,
  42. SCRIPT_ADDRESS,
  43. SECRET_KEY,
  44. EXT_PUBLIC_KEY,
  45. EXT_SECRET_KEY,
  46. MAX_BASE58_TYPES
  47. };
  48. const Consensus::Params& GetConsensus() const { return consensus; }
  49. const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
  50. int GetDefaultPort() const { return nDefaultPort; }
  51. const CBlock& GenesisBlock() const { return genesis; }
  52. /** Make miner wait to have peers to avoid wasting work */
  53. bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
  54. /** Default value for -checkmempool and -checkblockindex argument */
  55. bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
  56. /** Policy: Filter transactions that do not match well-defined patterns */
  57. bool RequireStandard() const { return fRequireStandard; }
  58. uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
  59. /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
  60. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  61. /** In the future use NetworkIDString() for RPC fields */
  62. bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
  63. /** Return the BIP70 network string (main, test or regtest) */
  64. std::string NetworkIDString() const { return strNetworkID; }
  65. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  66. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  67. const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
  68. const CCheckpointData& Checkpoints() const { return checkpointData; }
  69. protected:
  70. CChainParams() {}
  71. Consensus::Params consensus;
  72. CMessageHeader::MessageStartChars pchMessageStart;
  73. int nDefaultPort;
  74. uint64_t nPruneAfterHeight;
  75. std::vector<CDNSSeedData> vSeeds;
  76. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  77. std::string strNetworkID;
  78. CBlock genesis;
  79. std::vector<SeedSpec6> vFixedSeeds;
  80. bool fMiningRequiresPeers;
  81. bool fDefaultConsistencyChecks;
  82. bool fRequireStandard;
  83. bool fMineBlocksOnDemand;
  84. bool fTestnetToBeDeprecatedFieldRPC;
  85. CCheckpointData checkpointData;
  86. };
  87. /**
  88. * Return the currently selected parameters. This won't change after app
  89. * startup, except for unit tests.
  90. */
  91. const CChainParams &Params();
  92. /**
  93. * @returns CChainParams for the given BIP70 chain name.
  94. */
  95. CChainParams& Params(const std::string& chain);
  96. /**
  97. * Sets the params returned by Params() to those for the given BIP70 chain name.
  98. * @throws std::runtime_error when the chain is not supported.
  99. */
  100. void SelectParams(const std::string& chain);
  101. #endif // BITCOIN_CHAINPARAMS_H