Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string ArgsManager::GetChainName() const
- {
- auto get_net = [&](const std::string& arg) {
- LOCK(cs_args);
- util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
- /* ignore_default_section_config= */ false,
- /*ignore_nonpersistent=*/false,
- /* get_chain_name= */ true);
- return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
- };
- auto is_chain_arg_present = [&](const std:: string& arg, const bool is_persistent) {
- LOCK(cs_args);
- util::SettingsValue value = util::GetSetting(m_settings, /* section= */ "", SettingName(arg),
- /* ignore_default_section_config= */ is_persistent,
- /*ignore_nonpersistent=*/(!is_persistent),
- /* get_chain_name= */ true);
- return !value.isNull();
- };
- const bool fRegTest = get_net("-regtest");
- const bool fSigNet = get_net("-signet");
- const bool fTestNet = get_net("-testnet");
- const bool is_chain_arg_set_persistent = is_chain_arg_present("chain", /* is_persistent= */ true);
- const bool is_chain_arg_set_command_line = is_chain_arg_present("chain", /* is_persistent= */ false);
- const bool is_chain_arg_set = is_chain_arg_set_persistent || is_chain_arg_set_command_line;
- if ((int)is_chain_arg_set + (int)fRegTest + (int)fSigNet + (int)fTestNet > 1) {
- //check if m_settings has multiple chain commands. If so, throw error.
- std::string error{"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one."};
- if (is_chain_arg_set_persistent && is_chain_arg_set_command_line) {
- error += " -chain is set in both .conf and command line.";
- }
- throw std::runtime_error(error);
- }
- if (fRegTest)
- return CBaseChainParams::REGTEST;
- if (fSigNet) {
- return CBaseChainParams::SIGNET;
- }
- if (fTestNet)
- return CBaseChainParams::TESTNET;
- return GetArg("-chain", CBaseChainParams::MAIN);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement