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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "bignum.h"
  8. #include "uint256.h"
  9. #include "util.h"
  10. #include <vector>
  11. using namespace std;
  12. #define MESSAGE_START_SIZE 4
  13. typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
  14. class CAddress;
  15. class CBlock;
  16. struct CDNSSeedData {
  17. string name, host;
  18. CDNSSeedData(const string &strName, const string &strHost) : name(strName), host(strHost) {}
  19. };
  20. /**
  21. * CChainParams defines various tweakable parameters of a given instance of the
  22. * Bitcoin system. There are three: the main network on which people trade goods
  23. * and services, the public test network which gets reset from time to time and
  24. * a regression test mode which is intended for private networks only. It has
  25. * minimal difficulty to ensure that blocks can be found instantly.
  26. */
  27. class CChainParams
  28. {
  29. public:
  30. enum Network {
  31. MAIN,
  32. TESTNET,
  33. REGTEST,
  34. };
  35. enum Base58Type {
  36. PUBKEY_ADDRESS,
  37. SCRIPT_ADDRESS,
  38. 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 CBigNum& ProofOfWorkLimit() const { return bnProofOfWorkLimit; }
  46. int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; }
  47. virtual const CBlock& GenesisBlock() const = 0;
  48. virtual bool RequireRPCPassword() const { return true; }
  49. const string& DataDir() const { return strDataDir; }
  50. virtual Network NetworkID() const = 0;
  51. const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
  52. const std::vector<unsigned char> &Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
  53. virtual const vector<CAddress>& FixedSeeds() const = 0;
  54. int RPCPort() const { return nRPCPort; }
  55. protected:
  56. CChainParams() {};
  57. uint256 hashGenesisBlock;
  58. MessageStartChars pchMessageStart;
  59. // Raw pub key bytes for the broadcast alert signing key.
  60. vector<unsigned char> vAlertPubKey;
  61. int nDefaultPort;
  62. int nRPCPort;
  63. CBigNum bnProofOfWorkLimit;
  64. int nSubsidyHalvingInterval;
  65. string strDataDir;
  66. vector<CDNSSeedData> vSeeds;
  67. std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
  68. };
  69. /**
  70. * Return the currently selected parameters. This won't change after app startup
  71. * outside of the unit tests.
  72. */
  73. const CChainParams &Params();
  74. /** Sets the params returned by Params() to those for the given network. */
  75. void SelectParams(CChainParams::Network network);
  76. /**
  77. * Looks for -regtest or -testnet and then calls SelectParams as appropriate.
  78. * Returns false if an invalid combination is given.
  79. */
  80. bool SelectParamsFromCommandLine();
  81. inline bool TestNet() {
  82. // Note: it's deliberate that this returns "false" for regression test mode.
  83. return Params().NetworkID() == CChainParams::TESTNET;
  84. }
  85. #endif