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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "checkpoints.h"
  9. #include "consensus/params.h"
  10. #include "primitives/block.h"
  11. #include "protocol.h"
  12. #include <vector>
  13. struct CDNSSeedData {
  14. std::string name, host;
  15. CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
  16. };
  17. struct SeedSpec6 {
  18. uint8_t addr[16];
  19. uint16_t port;
  20. };
  21. /**
  22. * CChainParams defines various tweakable parameters of a given instance of the
  23. * Bitcoin system. There are three: the main network on which people trade goods
  24. * and services, the public test network which gets reset from time to time and
  25. * a regression test mode which is intended for private networks only. It has
  26. * minimal difficulty to ensure that blocks can be found instantly.
  27. */
  28. class CChainParams
  29. {
  30. public:
  31. enum Base58Type {
  32. PUBKEY_ADDRESS,
  33. SCRIPT_ADDRESS,
  34. SECRET_KEY,
  35. EXT_PUBLIC_KEY,
  36. EXT_SECRET_KEY,
  37. MAX_BASE58_TYPES
  38. };
  39. const Consensus::Params& GetConsensus() const { return consensus; }
  40. const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
  41. const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
  42. int GetDefaultPort() const { return nDefaultPort; }
  43. int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
  44. int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
  45. int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }
  46. int ToCheckBlockUpgradeMajority() const { return consensus.nMajorityWindow; }
  47. /** Used if GenerateBitcoins is called with a negative number of threads */
  48. int DefaultMinerThreads() const { return nMinerThreads; }
  49. const CBlock& GenesisBlock() const { return genesis; }
  50. bool RequireRPCPassword() const { return fRequireRPCPassword; }
  51. /** Make miner wait to have peers to avoid wasting work */
  52. bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
  53. /** Default value for -checkmempool and -checkblockindex argument */
  54. bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
  55. /** Make standard checks */
  56. bool RequireStandard() const { return fRequireStandard; }
  57. int64_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. virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
  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. int nMinerThreads;
  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 fRequireRPCPassword;
  83. bool fMiningRequiresPeers;
  84. bool fDefaultConsistencyChecks;
  85. bool fRequireStandard;
  86. bool fMineBlocksOnDemand;
  87. bool fTestnetToBeDeprecatedFieldRPC;
  88. };
  89. /**
  90. * Return the currently selected parameters. This won't change after app startup
  91. * outside of the unit tests.
  92. */
  93. const CChainParams &Params();
  94. /** Return parameters for the given network. */
  95. CChainParams &Params(CBaseChainParams::Network network);
  96. /** Sets the params returned by Params() to those for the given network. */
  97. void SelectParams(CBaseChainParams::Network network);
  98. /**
  99. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  100. * Returns false if an invalid combination is given.
  101. */
  102. bool SelectParamsFromCommandLine();
  103. #endif // BITCOIN_CHAINPARAMS_H