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.

chainparamsbase.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright (c) 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. #include "chainparamsbase.h"
  6. #include "util.h"
  7. #include <assert.h>
  8. /**
  9. * Main network
  10. */
  11. class CBaseMainParams : public CBaseChainParams
  12. {
  13. public:
  14. CBaseMainParams()
  15. {
  16. nRPCPort = 8332;
  17. }
  18. };
  19. static CBaseMainParams mainParams;
  20. /**
  21. * Testnet (v3)
  22. */
  23. class CBaseTestNetParams : public CBaseChainParams
  24. {
  25. public:
  26. CBaseTestNetParams()
  27. {
  28. nRPCPort = 18332;
  29. strDataDir = "testnet3";
  30. }
  31. };
  32. static CBaseTestNetParams testNetParams;
  33. /*
  34. * Regression test
  35. */
  36. class CBaseRegTestParams : public CBaseChainParams
  37. {
  38. public:
  39. CBaseRegTestParams()
  40. {
  41. nRPCPort = 18332;
  42. strDataDir = "regtest";
  43. }
  44. };
  45. static CBaseRegTestParams regTestParams;
  46. /*
  47. * Unit test
  48. */
  49. class CBaseUnitTestParams : public CBaseMainParams
  50. {
  51. public:
  52. CBaseUnitTestParams()
  53. {
  54. strDataDir = "unittest";
  55. }
  56. };
  57. static CBaseUnitTestParams unitTestParams;
  58. static CBaseChainParams* pCurrentBaseParams = 0;
  59. const CBaseChainParams& BaseParams()
  60. {
  61. assert(pCurrentBaseParams);
  62. return *pCurrentBaseParams;
  63. }
  64. void SelectBaseParams(CBaseChainParams::Network network)
  65. {
  66. switch (network) {
  67. case CBaseChainParams::MAIN:
  68. pCurrentBaseParams = &mainParams;
  69. break;
  70. case CBaseChainParams::TESTNET:
  71. pCurrentBaseParams = &testNetParams;
  72. break;
  73. case CBaseChainParams::REGTEST:
  74. pCurrentBaseParams = &regTestParams;
  75. break;
  76. default:
  77. assert(false && "Unimplemented network");
  78. return;
  79. }
  80. }
  81. CBaseChainParams::Network NetworkIdFromCommandLine()
  82. {
  83. bool fRegTest = GetBoolArg("-regtest", false);
  84. bool fTestNet = GetBoolArg("-testnet", false);
  85. if (fTestNet && fRegTest)
  86. return CBaseChainParams::MAX_NETWORK_TYPES;
  87. if (fRegTest)
  88. return CBaseChainParams::REGTEST;
  89. if (fTestNet)
  90. return CBaseChainParams::TESTNET;
  91. return CBaseChainParams::MAIN;
  92. }
  93. bool SelectBaseParamsFromCommandLine()
  94. {
  95. CBaseChainParams::Network network = NetworkIdFromCommandLine();
  96. if (network == CBaseChainParams::MAX_NETWORK_TYPES)
  97. return false;
  98. SelectBaseParams(network);
  99. return true;
  100. }
  101. bool AreBaseParamsConfigured()
  102. {
  103. return pCurrentBaseParams != NULL;
  104. }