Advertisement
KaizenKintsugi

Untitled

Aug 29th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. std::string ArgsManager::GetChainName() const
  2. {
  3. auto get_net = [&](const std::string& arg) {
  4. LOCK(cs_args);
  5. util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
  6. /* ignore_default_section_config= */ false,
  7. /*ignore_nonpersistent=*/false,
  8. /* get_chain_name= */ true);
  9. return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
  10. };
  11.  
  12. auto is_chain_arg_present = [&](const std:: string& arg, const bool is_persistent) {
  13. LOCK(cs_args);
  14. util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
  15. /* ignore_default_section_config= */ is_persistent,
  16. /*ignore_nonpersistent=*/(!is_persistent),
  17. /* get_chain_name= */ true);
  18. return !value.isNull();
  19. };
  20.  
  21. const bool fRegTest = get_net("-regtest");
  22. const bool fSigNet = get_net("-signet");
  23. const bool fTestNet = get_net("-testnet");
  24.  
  25. const bool is_chain_arg_set_persistent = is_chain_arg_present("chain", /* is_persistent= */ true);
  26. const bool is_chain_arg_set_command_line = is_chain_arg_present("chain", /* is_persistent= */ false);
  27. const bool is_chain_arg_set = is_chain_arg_set_persistent || is_chain_arg_set_command_line;
  28.  
  29. if ((int)is_chain_arg_set + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
  30. //check if m_settings has multiple chain commands. If so, throw error.
  31. std::string error{"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one."};
  32. if (is_chain_arg_set_persistent && is_chain_arg_set_command_line) {
  33. error += " -chain is set in both .conf and command line.";
  34. }
  35.  
  36. throw std::runtime_error(error);
  37. }
  38. if (fRegTest)
  39. return CBaseChainParams::REGTEST;
  40. if (fSigNet) {
  41. return CBaseChainParams::SIGNET;
  42. }
  43. if (fTestNet)
  44. return CBaseChainParams::TESTNET;
  45.  
  46. return GetArg("-chain", CBaseChainParams::MAIN);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement