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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "uint256.h"
  8. #include "core.h"
  9. #include "protocol.h"
  10. #include <vector>
  11. using namespace std;
  12. typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
  13. struct CDNSSeedData {
  14. string name, host;
  15. CDNSSeedData(const string &strName, const string &strHost) : name(strName), host(strHost) {}
  16. };
  17. /**
  18. * CChainParams defines various tweakable parameters of a given instance of the
  19. * Bitcoin system. There are three: the main network on which people trade goods
  20. * and services, the public test network which gets reset from time to time and
  21. * a regression test mode which is intended for private networks only. It has
  22. * minimal difficulty to ensure that blocks can be found instantly.
  23. */
  24. class CChainParams
  25. {
  26. public:
  27. enum Network {
  28. MAIN,
  29. TESTNET,
  30. REGTEST,
  31. MAX_NETWORK_TYPES
  32. };
  33. enum Base58Type {
  34. PUBKEY_ADDRESS,
  35. SCRIPT_ADDRESS,
  36. SECRET_KEY,
  37. EXT_PUBLIC_KEY,
  38. EXT_SECRET_KEY,
  39. MAX_BASE58_TYPES
  40. };
  41. const uint256& HashGenesisBlock() const { return hashGenesisBlock; }
  42. const MessageStartChars& MessageStart() const { return pchMessageStart; }
  43. const vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
  44. int GetDefaultPort() const { return nDefaultPort; }
  45. const uint256& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
  46. int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
  47. /* Used to check majorities for block version upgrade */
  48. int EnforceBlockUpgradeMajority() const { return nEnforceBlockUpgradeMajority; }
  49. int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
  50. int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
  51. /* Used if GenerateBitcoins is called with a negative number of threads */
  52. int DefaultMinerThreads() const { return nMinerThreads; }
  53. const CBlock& GenesisBlock() const { return genesis; };
  54. bool RequireRPCPassword() const { return fRequireRPCPassword; }
  55. /* Make miner wait to have peers to avoid wasting work */
  56. bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
  57. /* Default value for -checkmempool argument */
  58. bool DefaultCheckMemPool() const { return fDefaultCheckMemPool; }
  59. /* Allow mining of a min-difficulty block */
  60. bool AllowMinDifficultyBlocks() const { return fAllowMinDifficultyBlocks; }
  61. /* Make standard checks */
  62. bool RequireStandard() const { return fRequireStandard; }
  63. /* Make standard checks */
  64. bool RPCisTestNet() const { return fRPCisTestNet; }
  65. const string& DataDir() const { return strDataDir; }
  66. /* Make miner stop after a block is found. In RPC, don't return
  67. * until nGenProcLimit blocks are generated */
  68. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  69. Network NetworkID() const { return networkID; }
  70. const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  71. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  72. const vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  73. int RPCPort() const { return nRPCPort; }
  74. protected:
  75. CChainParams() {}
  76. uint256 hashGenesisBlock;
  77. MessageStartChars pchMessageStart;
  78. // Raw pub key bytes for the broadcast alert signing key.
  79. vector<unsigned char> vAlertPubKey;
  80. int nDefaultPort;
  81. int nRPCPort;
  82. uint256 bnProofOfWorkLimit;
  83. int nSubsidyHalvingInterval;
  84. int nEnforceBlockUpgradeMajority;
  85. int nRejectBlockOutdatedMajority;
  86. int nToCheckBlockUpgradeMajority;
  87. string strDataDir;
  88. int nMinerThreads;
  89. vector<CDNSSeedData> vSeeds;
  90. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  91. Network networkID;
  92. CBlock genesis;
  93. vector<CAddress> vFixedSeeds;
  94. bool fRequireRPCPassword;
  95. bool fMiningRequiresPeers;
  96. bool fDefaultCheckMemPool;
  97. bool fAllowMinDifficultyBlocks;
  98. bool fRequireStandard;
  99. bool fRPCisTestNet;
  100. bool fMineBlocksOnDemand;
  101. };
  102. /**
  103. * Return the currently selected parameters. This won't change after app startup
  104. * outside of the unit tests.
  105. */
  106. const CChainParams &Params();
  107. /** Sets the params returned by Params() to those for the given network. */
  108. void SelectParams(CChainParams::Network network);
  109. /**
  110. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  111. * Returns false if an invalid combination is given.
  112. */
  113. bool SelectParamsFromCommandLine();
  114. #endif