MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetChainArg

Method GetChainArg

src/common/args.cpp:926–956  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

924}
925
926std::variant<ChainType, std::string> ArgsManager::GetChainArg() const
927{
928 auto get_net = [&](const std::string& arg) {
929 LOCK(cs_args);
930 common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),
931 /* ignore_default_section_config= */ false,
932 /*ignore_nonpersistent=*/false,
933 /* get_chain_type= */ true);
934 return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());
935 };
936
937 const bool fRegTest = get_net("-regtest");
938 const bool fSigNet = get_net("-signet");
939 const bool fTestNet = get_net("-testnet");
940 const bool fTestNet4 = get_net("-testnet4");
941 const auto chain_arg = GetArg("-chain");
942
943 if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet + (int)fTestNet4 > 1) {
944 throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet, -testnet4 and -chain. Can use at most one.");
945 }
946 if (chain_arg) {
947 if (auto parsed = ChainTypeFromString(*chain_arg)) return *parsed;
948 // Not a known string, so return original string
949 return *chain_arg;
950 }
951 if (fRegTest) return ChainType::REGTEST;
952 if (fSigNet) return ChainType::SIGNET;
953 if (fTestNet) return ChainType::TESTNET;
954 if (fTestNet4) return ChainType::TESTNET4;
955 return ChainType::MAIN;
956}
957
958bool ArgsManager::UseDefaultSection(const std::string& arg) const
959{

Callers

nothing calls this directly

Calls 8

GetSettingFunction · 0.85
InterpretBoolFunction · 0.85
ChainTypeFromStringFunction · 0.85
isNullMethod · 0.80
isBoolMethod · 0.80
get_boolMethod · 0.80
SettingNameFunction · 0.70
has_valueMethod · 0.45

Tested by

no test coverage detected