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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "arith_uint256.h"
  8. #include "chainparamsbase.h"
  9. #include "checkpoints.h"
  10. #include "consensus/params.h"
  11. #include "primitives/block.h"
  12. #include "protocol.h"
  13. #include <vector>
  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 Consensus::Params& GetConsensus() const { return consensus; }
  37. const uint256& HashGenesisBlock() const { return consensus.hashGenesisBlock; }
  38. const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; }
  39. const std::vector<unsigned char>& AlertKey() const { return vAlertPubKey; }
  40. int GetDefaultPort() const { return nDefaultPort; }
  41. const arith_uint256& ProofOfWorkLimit() const { return consensus.powLimit; }
  42. int SubsidyHalvingInterval() const { return consensus.nSubsidyHalvingInterval; }
  43. int EnforceBlockUpgradeMajority() const { return consensus.nMajorityEnforceBlockUpgrade; }
  44. int RejectBlockOutdatedMajority() const { return consensus.nMajorityRejectBlockOutdated; }
  45. int ToCheckBlockUpgradeMajority() const { return consensus.nMajorityWindow; }
  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 and -checkblockindex argument */
  53. bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
  54. /** Allow mining of a min-difficulty block */
  55. bool AllowMinDifficultyBlocks() const { return consensus.fPowAllowMinDifficultyBlocks; }
  56. /** Make standard checks */
  57. bool RequireStandard() const { return fRequireStandard; }
  58. int64_t TargetTimespan() const { return consensus.nPowTargetTimespan; }
  59. int64_t TargetSpacing() const { return consensus.nPowTargetSpacing; }
  60. int64_t DifficultyAdjustmentInterval() const { return consensus.nPowTargetTimespan / consensus.nPowTargetSpacing; }
  61. /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
  62. bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
  63. /** In the future use NetworkIDString() for RPC fields */
  64. bool TestnetToBeDeprecatedFieldRPC() const { return fTestnetToBeDeprecatedFieldRPC; }
  65. /** Return the BIP70 network string (main, test or regtest) */
  66. std::string NetworkIDString() const { return strNetworkID; }
  67. const std::vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  68. const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  69. const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
  70. virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
  71. protected:
  72. CChainParams() {}
  73. Consensus::Params consensus;
  74. CMessageHeader::MessageStartChars pchMessageStart;
  75. //! Raw pub key bytes for the broadcast alert signing key.
  76. std::vector<unsigned char> vAlertPubKey;
  77. int nDefaultPort;
  78. int nMinerThreads;
  79. std::vector<CDNSSeedData> vSeeds;
  80. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  81. std::string strNetworkID;
  82. CBlock genesis;
  83. std::vector<CAddress> vFixedSeeds;
  84. bool fRequireRPCPassword;
  85. bool fMiningRequiresPeers;
  86. bool fDefaultConsistencyChecks;
  87. bool fRequireStandard;
  88. bool fMineBlocksOnDemand;
  89. bool fTestnetToBeDeprecatedFieldRPC;
  90. };
  91. /**
  92. * Return the currently selected parameters. This won't change after app startup
  93. * outside of the unit tests.
  94. */
  95. const CChainParams &Params();
  96. /** Return parameters for the given network. */
  97. CChainParams &Params(CBaseChainParams::Network network);
  98. /** Sets the params returned by Params() to those for the given network. */
  99. void SelectParams(CBaseChainParams::Network network);
  100. /**
  101. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  102. * Returns false if an invalid combination is given.
  103. */
  104. bool SelectParamsFromCommandLine();
  105. #endif // BITCOIN_CHAINPARAMS_H