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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (c) 2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2017 The Starwels 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 <tinyformat.h>
  7. #include <util.h>
  8. #include <assert.h>
  9. const std::string CBaseChainParams::MAIN = "main";
  10. const std::string CBaseChainParams::AI = "test";
  11. const std::string CBaseChainParams::REGTEST = "regtest";
  12. void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
  13. {
  14. strUsage += HelpMessageGroup(_("Chain selection options:"));
  15. strUsage += HelpMessageOpt("-ai", _("Use the test chain"));
  16. if (debugHelp) {
  17. strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
  18. "This is intended for regression testing tools and app development.");
  19. }
  20. }
  21. /**
  22. * Main network
  23. */
  24. class CBaseMainParams : public CBaseChainParams
  25. {
  26. public:
  27. CBaseMainParams()
  28. {
  29. nRPCPort = 8342;
  30. }
  31. };
  32. /**
  33. * Ai (v3)
  34. */
  35. class CBaseTestNetParams : public CBaseChainParams
  36. {
  37. public:
  38. CBaseTestNetParams()
  39. {
  40. nRPCPort = 8332;
  41. strDataDir = "ai";
  42. }
  43. };
  44. /*
  45. * Regression test
  46. */
  47. class CBaseRegTestParams : public CBaseChainParams
  48. {
  49. public:
  50. CBaseRegTestParams()
  51. {
  52. nRPCPort = 18443;
  53. strDataDir = "regtest";
  54. }
  55. };
  56. static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
  57. const CBaseChainParams& BaseParams()
  58. {
  59. assert(globalChainBaseParams);
  60. return *globalChainBaseParams;
  61. }
  62. std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
  63. {
  64. if (chain == CBaseChainParams::MAIN)
  65. return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
  66. else if (chain == CBaseChainParams::AI)
  67. return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
  68. else if (chain == CBaseChainParams::REGTEST)
  69. return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
  70. else
  71. throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  72. }
  73. void SelectBaseParams(const std::string& chain)
  74. {
  75. globalChainBaseParams = CreateBaseChainParams(chain);
  76. }
  77. std::string ChainNameFromCommandLine()
  78. {
  79. bool fRegTest = gArgs.GetBoolArg("-regtest", false);
  80. bool fTestNet = gArgs.GetBoolArg("-ai", false);
  81. if (fTestNet && fRegTest)
  82. throw std::runtime_error("Invalid combination of -regtest and -ai.");
  83. if (fRegTest)
  84. return CBaseChainParams::REGTEST;
  85. if (fTestNet)
  86. return CBaseChainParams::AI;
  87. return CBaseChainParams::MAIN;
  88. }