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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2014 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 PruneAfterHeight() const { return nPruneAfterHeight; }
  57. /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
  58. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  59. /** In the future use NetworkIDString() for RPC fields */
  60. bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
  61. /** Return the BIP70 network string (main, test or regtest) */
  62. std::string NetworkIDString() const { return strNetworkID; }
  63. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  64. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  65. const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
  66. const CCheckpointData& Checkpoints() const { return checkpointData; }
  67. protected:
  68. CChainParams() {}
  69. Consensus::Params consensus;
  70. CMessageHeader::MessageStartChars pchMessageStart;
  71. //! Raw pub key bytes for the broadcast alert signing key.
  72. std::vector<unsigned char> vAlertPubKey;
  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. /**
  102. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  103. * Returns false if an invalid combination is given.
  104. */
  105. bool SelectParamsFromCommandLine();
  106. #endif // BITCOIN_CHAINPARAMS_H