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.3KB

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