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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "chainparamsbase.h"
  8. #include "checkpoints.h"
  9. #include "core/block.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. /* Return the BIP70 network string (main, test or regtest) */
  69. std::string NetworkIDString() const { return strNetworkID; }
  70. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  71. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  72. const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  73. virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
  74. protected:
  75. CChainParams() {}
  76. uint256 hashGenesisBlock;
  77. MessageStartChars pchMessageStart;
  78. // Raw pub key bytes for the broadcast alert signing key.
  79. std::vector<unsigned char> vAlertPubKey;
  80. int nDefaultPort;
  81. uint256 bnProofOfWorkLimit;
  82. int nSubsidyHalvingInterval;
  83. int nEnforceBlockUpgradeMajority;
  84. int nRejectBlockOutdatedMajority;
  85. int nToCheckBlockUpgradeMajority;
  86. int64_t nTargetTimespan;
  87. int64_t nTargetSpacing;
  88. int nMinerThreads;
  89. std::vector<CDNSSeedData> vSeeds;
  90. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  91. CBaseChainParams::Network networkID;
  92. std::string strNetworkID;
  93. CBlock genesis;
  94. std::vector<CAddress> vFixedSeeds;
  95. bool fRequireRPCPassword;
  96. bool fMiningRequiresPeers;
  97. bool fDefaultCheckMemPool;
  98. bool fAllowMinDifficultyBlocks;
  99. bool fRequireStandard;
  100. bool fMineBlocksOnDemand;
  101. bool fSkipProofOfWorkCheck;
  102. bool fTestnetToBeDeprecatedFieldRPC;
  103. };
  104. /** Modifiable parameters interface is used by test cases to adapt the parameters in order
  105. *** to test specific features more easily. Test cases should always restore the previous
  106. *** values after finalization.
  107. **/
  108. class CModifiableParams {
  109. public:
  110. // Published setters to allow changing values in unit test cases
  111. virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) =0;
  112. virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority)=0;
  113. virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority)=0;
  114. virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority)=0;
  115. virtual void setDefaultCheckMemPool(bool aDefaultCheckMemPool)=0;
  116. virtual void setAllowMinDifficultyBlocks(bool aAllowMinDifficultyBlocks)=0;
  117. virtual void setSkipProofOfWorkCheck(bool aSkipProofOfWorkCheck)=0;
  118. };
  119. /**
  120. * Return the currently selected parameters. This won't change after app startup
  121. * outside of the unit tests.
  122. */
  123. const CChainParams &Params();
  124. /** Return parameters for the given network. */
  125. CChainParams &Params(CBaseChainParams::Network network);
  126. /** Get modifyable network parameters (UNITTEST only) */
  127. CModifiableParams *ModifiableParams();
  128. /** Sets the params returned by Params() to those for the given network. */
  129. void SelectParams(CBaseChainParams::Network network);
  130. /**
  131. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  132. * Returns false if an invalid combination is given.
  133. */
  134. bool SelectParamsFromCommandLine();
  135. #endif // BITCOIN_CHAIN_PARAMS_H