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 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2013 The Bitcoin developers
  3. // Distributed under the MIT/X11 software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef BITCOIN_CHAIN_PARAMS_H
  6. #define BITCOIN_CHAIN_PARAMS_H
  7. #include "core.h"
  8. #include "chainparamsbase.h"
  9. #include "checkpoints.h"
  10. #include "protocol.h"
  11. #include "uint256.h"
  12. #include <vector>
  13. typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
  14. struct CDNSSeedData {
  15. std::string name, host;
  16. CDNSSeedData(const std::string &strName, const std::string &strHost) : name(strName), host(strHost) {}
  17. };
  18. /**
  19. * CChainParams defines various tweakable parameters of a given instance of the
  20. * Bitcoin system. There are three: the main network on which people trade goods
  21. * and services, the public test network which gets reset from time to time and
  22. * a regression test mode which is intended for private networks only. It has
  23. * minimal difficulty to ensure that blocks can be found instantly.
  24. */
  25. class CChainParams
  26. {
  27. public:
  28. enum Base58Type {
  29. PUBKEY_ADDRESS,
  30. SCRIPT_ADDRESS,
  31. SECRET_KEY,
  32. EXT_PUBLIC_KEY,
  33. EXT_SECRET_KEY,
  34. MAX_BASE58_TYPES
  35. };
  36. const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
  37. const MessageStartChars& MessageStart() const { return pchMessageStart; }
  38. const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
  39. int GetDefaultPort() const { return nDefaultPort; }
  40. const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
  41. int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
  42. /* Used to check majorities for block version upgrade */
  43. int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; }
  44. int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
  45. int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
  46. /* Used if GenerateBitcoins is called with a negative number of threads */
  47. int DefaultMinerThreads() const { return nMinerThreads; }
  48. const CBlock& GenesisBlock() const { return genesis; }
  49. bool RequireRPCPassword() const { return fRequireRPCPassword; }
  50. /* Make miner wait to have peers to avoid wasting work */
  51. bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
  52. /* Default value for -checkmempool argument */
  53. bool DefaultCheckMemPool() const { return fDefaultCheckMemPool; }
  54. /* Allow mining of a min-difficulty block */
  55. bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
  56. /* Skip proof-of-work check: allow mining of any difficulty block */
  57. bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
  58. /* Make standard checks */
  59. bool RequireStandard() const { return fRequireStandard; }
  60. int64_t TargetTimespan() const { return nTargetTimespan; }
  61. int64_t TargetSpacing() const { return nTargetSpacing; }
  62. int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }
  63. /* Make miner stop after a block is found. In RPC, don't return
  64. * until nGenProcLimit blocks are generated */
  65. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  66. /* In the future use NetworkIDString() for RPC fields */
  67. bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
  68. CBaseChainParams::Network NetworkID() const { return networkID; }
  69. /* Return the BIP70 network string (main, test or regtest) */
  70. std::string NetworkIDString() const { return strNetworkID; }
  71. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  72. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  73. const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  74. virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
  75. protected:
  76. CChainParams() {}
  77. uint256 hashGenesisBlock;
  78. MessageStartChars pchMessageStart;
  79. // Raw pub key bytes for the broadcast alert signing key.
  80. std::vector<unsigned char> vAlertPubKey;
  81. int nDefaultPort;
  82. uint256 bnProofOfWorkLimit;
  83. int nSubsidyHalvingInterval;
  84. int nEnforceBlockUpgradeMajority;
  85. int nRejectBlockOutdatedMajority;
  86. int nToCheckBlockUpgradeMajority;
  87. int64_t nTargetTimespan;
  88. int64_t nTargetSpacing;
  89. int nMinerThreads;
  90. std::vector<CDNSSeedData> vSeeds;
  91. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  92. CBaseChainParams::Network networkID;
  93. std::string strNetworkID;
  94. CBlock genesis;
  95. std::vector<CAddress> vFixedSeeds;
  96. bool fRequireRPCPassword;
  97. bool fMiningRequiresPeers;
  98. bool fDefaultCheckMemPool;
  99. bool fAllowMinDifficultyBlocks;
  100. bool fRequireStandard;
  101. bool fMineBlocksOnDemand;
  102. bool fSkipProofOfWorkCheck;
  103. bool fTestnetToBeDeprecatedFieldRPC;
  104. };
  105. /** Modifiable parameters interface is used by test cases to adapt the parameters in order
  106. *** to test specific features more easily. Test cases should always restore the previous
  107. *** values after finalization.
  108. **/
  109. class CModifiableParams {
  110. public:
  111. // Published setters to allow changing values in unit test cases
  112. virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) =0;
  113. virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority)=0;
  114. virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority)=0;
  115. virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority)=0;
  116. virtual void setDefaultCheckMemPool(bool aDefaultCheckMemPool)=0;
  117. virtual void setAllowMinDifficultyBlocks(bool aAllowMinDifficultyBlocks)=0;
  118. virtual void setSkipProofOfWorkCheck(bool aSkipProofOfWorkCheck)=0;
  119. };
  120. /**
  121. * Return the currently selected parameters. This won't change after app startup
  122. * outside of the unit tests.
  123. */
  124. const CChainParams &Params();
  125. /** Return parameters for the given network. */
  126. CChainParams &Params(CBaseChainParams::Network network);
  127. /** Get modifyable network parameters (UNITTEST only) */
  128. CModifiableParams *ModifiableParams();
  129. /** Sets the params returned by Params() to those for the given network. */
  130. void SelectParams(CBaseChainParams::Network network);
  131. /**
  132. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  133. * Returns false if an invalid combination is given.
  134. */
  135. bool SelectParamsFromCommandLine();
  136. #endif // BITCOIN_CHAIN_PARAMS_H