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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (c) 2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2015 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 "tinyformat.h"
  7. #include "util.h"
  8. #include <assert.h>
  9. const std::string CBaseChainParams::MAIN = "main";
  10. const std::string CBaseChainParams::TESTNET = "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("-testnet", _("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 = 8332;
  30. }
  31. };
  32. static CBaseMainParams mainParams;
  33. /**
  34. * Testnet (v3)
  35. */
  36. class CBaseTestNetParams : public CBaseChainParams
  37. {
  38. public:
  39. CBaseTestNetParams()
  40. {
  41. nRPCPort = 18332;
  42. strDataDir = "testnet3";
  43. }
  44. };
  45. static CBaseTestNetParams testNetParams;
  46. /*
  47. * Regression test
  48. */
  49. class CBaseRegTestParams : public CBaseChainParams
  50. {
  51. public:
  52. CBaseRegTestParams()
  53. {
  54. nRPCPort = 18332;
  55. strDataDir = "regtest";
  56. }
  57. };
  58. static CBaseRegTestParams regTestParams;
  59. static CBaseChainParams* pCurrentBaseParams = 0;
  60. const CBaseChainParams& BaseParams()
  61. {
  62. assert(pCurrentBaseParams);
  63. return *pCurrentBaseParams;
  64. }
  65. CBaseChainParams& BaseParams(const std::string& chain)
  66. {
  67. if (chain == CBaseChainParams::MAIN)
  68. return mainParams;
  69. else if (chain == CBaseChainParams::TESTNET)
  70. return testNetParams;
  71. else if (chain == CBaseChainParams::REGTEST)
  72. return regTestParams;
  73. else
  74. throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
  75. }
  76. void SelectBaseParams(const std::string& chain)
  77. {
  78. pCurrentBaseParams = &BaseParams(chain);
  79. }
  80. std::string ChainNameFromCommandLine()
  81. {
  82. bool fRegTest = GetBoolArg("-regtest", false);
  83. bool fTestNet = GetBoolArg("-testnet", false);
  84. if (fTestNet && fRegTest)
  85. throw std::runtime_error("Invalid combination of -regtest and -testnet.");
  86. if (fRegTest)
  87. return CBaseChainParams::REGTEST;
  88. if (fTestNet)
  89. return CBaseChainParams::TESTNET;
  90. return CBaseChainParams::MAIN;
  91. }
  92. bool AreBaseParamsConfigured()
  93. {
  94. return pCurrentBaseParams != NULL;
  95. }