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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /**
  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 Base58Type {
  28. PUBKEY_ADDRESS,
  29. SCRIPT_ADDRESS,
  30. SECRET_KEY,
  31. EXT_PUBLIC_KEY,
  32. EXT_SECRET_KEY,
  33. MAX_BASE58_TYPES
  34. };
  35. const Consensus::Params& GetConsensus() const { return consensus; }
  36. const uint256& HashGenesisBlock() const { return consensus.hashGenesisBlock; }
  37. const CMessageHeader::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 consensus.powLimit; }
  41. int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
  42. int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
  43. int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }
  44. int ToCheckBlockUpgradeMajority() const { return consensus.nMajorityWindow; }
  45. /** Used if GenerateBitcoins is called with a negative number of threads */
  46. int DefaultMinerThreads() const { return nMinerThreads; }
  47. const CBlock& GenesisBlock() const { return genesis; }
  48. bool RequireRPCPassword() const { return fRequireRPCPassword; }
  49. /** Make miner wait to have peers to avoid wasting work */
  50. bool MiningRequiresPeers() const { return fMiningRequiresPeers; }
  51. /** Default value for -checkmempool and -checkblockindex argument */
  52. bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
  53. /** Allow mining of a min-difficulty block */
  54. bool AllowMinDifficultyBlocks() const { return consensus.fPowAllowMinDifficultyBlocks; }
  55. /** Make standard checks */
  56. bool RequireStandard() const { return fRequireStandard; }
  57. int64_t TargetTimespan() const { return consensus.nPowTargetTimespan; }
  58. int64_t TargetSpacing() const { return consensus.nPowTargetSpacing; }
  59. int64_t DifficultyAdjustmentInterval() const { return consensus.nPowTargetTimespan / consensus.nPowTargetSpacing; }
  60. /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
  61. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  62. /** In the future use NetworkIDString() for RPC fields */
  63. bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
  64. /** Return the BIP70 network string (main, test or regtest) */
  65. std::string NetworkIDString() const { return strNetworkID; }
  66. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  67. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  68. const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  69. virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
  70. protected:
  71. CChainParams() {}
  72. Consensus::Params consensus;
  73. CMessageHeader::MessageStartChars pchMessageStart;
  74. //! Raw pub key bytes for the broadcast alert signing key.
  75. std::vector<unsigned char> vAlertPubKey;
  76. int nDefaultPort;
  77. int nMinerThreads;
  78. std::vector<CDNSSeedData> vSeeds;
  79. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  80. std::string strNetworkID;
  81. CBlock genesis;
  82. std::vector<CAddress> vFixedSeeds;
  83. bool fRequireRPCPassword;
  84. bool fMiningRequiresPeers;
  85. bool fDefaultConsistencyChecks;
  86. bool fRequireStandard;
  87. bool fMineBlocksOnDemand;
  88. bool fTestnetToBeDeprecatedFieldRPC;
  89. };
  90. /**
  91. * Return the currently selected parameters. This won't change after app startup
  92. * outside of the unit tests.
  93. */
  94. const CChainParams &Params();
  95. /** Return parameters for the given network. */
  96. CChainParams &Params(CBaseChainParams::Network network);
  97. /** Sets the params returned by Params() to those for the given network. */
  98. void SelectParams(CBaseChainParams::Network network);
  99. /**
  100. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  101. * Returns false if an invalid combination is given.
  102. */
  103. bool SelectParamsFromCommandLine();
  104. #endif // BITCOIN_CHAINPARAMS_H