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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "protocol.h"
  9. #include "uint256.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. /* Return the BIP70 network string (main, test or regtest) */
  71. std::string NetworkIDString() const { return strNetworkID; }
  72. const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  73. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  74. const vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  75. int RPCPort() const { return nRPCPort; }
  76. protected:
  77. CChainParams() {}
  78. uint256 hashGenesisBlock;
  79. MessageStartChars pchMessageStart;
  80. // Raw pub key bytes for the broadcast alert signing key.
  81. vector<unsigned char> vAlertPubKey;
  82. int nDefaultPort;
  83. int nRPCPort;
  84. uint256 bnProofOfWorkLimit;
  85. int nSubsidyHalvingInterval;
  86. int nEnforceBlockUpgradeMajority;
  87. int nRejectBlockOutdatedMajority;
  88. int nToCheckBlockUpgradeMajority;
  89. string strDataDir;
  90. int nMinerThreads;
  91. vector<CDNSSeedData> vSeeds;
  92. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  93. Network networkID;
  94. std::string strNetworkID;
  95. CBlock genesis;
  96. vector<CAddress> vFixedSeeds;
  97. bool fRequireRPCPassword;
  98. bool fMiningRequiresPeers;
  99. bool fDefaultCheckMemPool;
  100. bool fAllowMinDifficultyBlocks;
  101. bool fRequireStandard;
  102. bool fRPCisTestNet;
  103. bool fMineBlocksOnDemand;
  104. };
  105. /**
  106. * Return the currently selected parameters. This won't change after app startup
  107. * outside of the unit tests.
  108. */
  109. const CChainParams &Params();
  110. /** Sets the params returned by Params() to those for the given network. */
  111. void SelectParams(CChainParams::Network network);
  112. /**
  113. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  114. * Returns false if an invalid combination is given.
  115. */
  116. bool SelectParamsFromCommandLine();
  117. #endif