Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
751break;752case OptionsCategory::NODE_RELAY:753usage += HelpMessageGroup("Node relay options:");754break;755case OptionsCategory::BLOCK_CREATION:756usage += HelpMessageGroup("Block creation options:");757break;758case OptionsCategory::RPC:759usage += HelpMessageGroup("RPC server options:");760break;761case OptionsCategory::IPC:762usage += HelpMessageGroup("IPC interprocess connection options:");763break;764case OptionsCategory::WALLET:765usage += HelpMessageGroup("Wallet options:");766break;767case OptionsCategory::WALLET_DEBUG_TEST:768if (show_debug) usage += HelpMessageGroup("Wallet debugging/testing options:");769break;770case OptionsCategory::CHAINPARAMS:771usage += HelpMessageGroup("Chain selection options:");772break;773case OptionsCategory::GUI:774usage += HelpMessageGroup("UI Options:");775break;776case OptionsCategory::COMMANDS:777usage += HelpMessageGroup("Commands:");778break;779case OptionsCategory::REGISTER_COMMANDS:780usage += HelpMessageGroup("Register Commands:");781break;782case OptionsCategory::CLI_COMMANDS:783usage += HelpMessageGroup("CLI Commands:");784break;785case OptionsCategory::COMMAND_OPTIONS:786case OptionsCategory::HIDDEN:787break;788} // no default case, so the compiler can warn about missing cases790if (category == OptionsCategory::COMMAND_OPTIONS) continue;792// When we get to the hidden options, stop793if (category == OptionsCategory::HIDDEN) break;795for (const auto& [arg_name, arg_info] : category_args) {796if (show_debug || !(arg_info.m_flags & ArgsManager::DEBUG_ONLY)) {797usage += HelpMessageOpt(arg_name, arg_info.m_help_param, arg_info.m_help_text);799if (category == OptionsCategory::COMMANDS) {800const auto cmd_args = m_command_args.find(arg_name);801if (cmd_args == m_command_args.end()) continue;802for_matching_cmd_opts(cmd_args->second, [&](const auto& cmdopt_name, const auto& cmdopt_info) {803usage += HelpMessageOpt(cmdopt_name, cmdopt_info.m_help_param, cmdopt_info.m_help_text, /*subopt=*/true);804});805}806}807}808}809return usage;810}812bool HelpRequested(const ArgsManager& args)813{814return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help") || args.IsArgSet("-help-debug");815}817void SetupHelpOptions(ArgsManager& args)818{819args.AddArg("-help", "Print this help message and exit (also -h or -?)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);820args.AddHiddenArgs({"-h", "-?"});821}823std::string HelpMessageGroup(const std::string &message) {824return std::string(message) + std::string("\n\n");825}827std::string HelpMessageOpt(std::string_view option, std::string_view help_param, std::string_view message, bool subopt)828{829constexpr int screen_width = 79;830int opt_indent = 2;831int msg_indent = 7;833if (subopt) {834int bump = msg_indent - opt_indent;835opt_indent += bump; // opt_indent now at the old msg_indent level836msg_indent += bump; // indent by the same amount837}838int msg_width = screen_width - msg_indent;840return strprintf("%*s%s%s\n%*s%s\n\n",841opt_indent, "", option, help_param,842msg_indent, "", FormatParagraph(message, msg_width, msg_indent));843}845const std::vector<std::string> TEST_OPTIONS_DOC{846"addrman (use deterministic addrman)",847"reindex_after_failure_noninteractive_yes (When asked for a reindex after failure interactively, simulate as-if answered with 'yes')",848"bip94 (enforce BIP94 consensus rules)",849};851bool HasTestOption(const ArgsManager& args, const std::string& test_option)852{853const auto options = args.GetArgs("-test");854return std::any_of(options.begin(), options.end(), [test_option](const auto& option) {855return option == test_option;856});857}859fs::path GetDefaultDataDir()860{861// Windows:862// old: C:\Users\Username\AppData\Roaming\Bitcoin863// new: C:\Users\Username\AppData\Local\Bitcoin864// macOS: ~/Library/Application Support/Bitcoin865// Unix-like: ~/.bitcoin866#ifdef WIN32867// Windows868// Check for existence of datadir in old location and keep it there869fs::path legacy_path = GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";870if (fs::exists(legacy_path)) return legacy_path;872// Otherwise, fresh installs can start in the new, "proper" location873return GetSpecialFolderPath(CSIDL_LOCAL_APPDATA) / "Bitcoin";874#else875fs::path pathRet;876char* pszHome = getenv("HOME");877if (pszHome == nullptr || strlen(pszHome) == 0)878pathRet = fs::path("/");879else880pathRet = fs::path(pszHome);881#ifdef __APPLE__882// macOS883return pathRet / "Library/Application Support/Bitcoin";884#else885// Unix-like886return pathRet / ".bitcoin";887#endif888#endif889}891bool CheckDataDirOption(const ArgsManager& args)892{893const fs::path datadir{args.GetPathArg("-datadir")};894return datadir.empty() || fs::is_directory(fs::absolute(datadir));895}897fs::path ArgsManager::GetConfigFilePath() const898{899LOCK(cs_args);900return *Assert(m_config_path);901}903void ArgsManager::SetConfigFilePath(fs::path path)904{905LOCK(cs_args);906assert(!m_config_path);907m_config_path = path;908}910ChainType ArgsManager::GetChainType() const911{912std::variant<ChainType, std::string> arg = GetChainArg();913if (auto* parsed = std::get_if<ChainType>(&arg)) return *parsed;914throw std::runtime_error(strprintf("Unknown chain %s.", std::get<std::string>(arg)));915}917std::string ArgsManager::GetChainTypeString() const918{919auto arg = GetChainArg();920if (auto* parsed = std::get_if<ChainType>(&arg)) return ChainTypeToString(*parsed);921return std::get<std::string>(arg);922}924std::variant<ChainType, std::string> ArgsManager::GetChainArg() const925{926auto get_net = [&](const std::string& arg) {927LOCK(cs_args);928common::SettingsValue value = common::GetSetting(m_settings, /* section= */ "", SettingName(arg),929/* ignore_default_section_config= */ false,930/*ignore_nonpersistent=*/false,931/* get_chain_type= */ true);932return value.isNull() ? false : value.isBool() ? value.get_bool() : InterpretBool(value.get_str());933};935const bool fRegTest = get_net("-regtest");936const bool fSigNet = get_net("-signet");937const bool fTestNet = get_net("-testnet");938const bool fTestNet4 = get_net("-testnet4");939const auto chain_arg = GetArg("-chain");941if ((int)chain_arg.has_value() + (int)fRegTest + (int)fSigNet + (int)fTestNet + (int)fTestNet4 > 1) {942throw std::runtime_error("Invalid combination of -regtest, -signet, -testnet, -testnet4 and -chain. Can use at most one.");943}944if (chain_arg) {945if (auto parsed = ChainTypeFromString(*chain_arg)) return *parsed;946// Not a known string, so return original string947return *chain_arg;948}949if (fRegTest) return ChainType::REGTEST;950if (fSigNet) return ChainType::SIGNET;951if (fTestNet) return ChainType::TESTNET;952if (fTestNet4) return ChainType::TESTNET4;953return ChainType::MAIN;954}956bool ArgsManager::UseDefaultSection(const std::string& arg) const957{958AssertLockHeld(cs_args);959return m_network == ChainTypeToString(ChainType::MAIN) || !m_network_only_args.contains(arg);960}962common::SettingsValue ArgsManager::GetSetting_(const std::string& arg) const963{964AssertLockHeld(cs_args);965return common::GetSetting(966m_settings, m_network, SettingName(arg), !UseDefaultSection(arg),967/*ignore_nonpersistent=*/false, /*get_chain_type=*/false);968}970common::SettingsValue ArgsManager::GetSetting(const std::string& arg) const971{972LOCK(cs_args);973return GetSetting_(arg);974}976std::vector<common::SettingsValue> ArgsManager::GetSettingsList(const std::string& arg) const977{978LOCK(cs_args);979return common::GetSettingsList(m_settings, m_network, SettingName(arg), !UseDefaultSection(arg));980}982void ArgsManager::logArgsPrefix(983const std::string& prefix,984const std::string& section,985const std::map<std::string, std::vector<common::SettingsValue>>& args) const986{987AssertLockHeld(cs_args);988std::string section_str = section.empty() ? "" : "[" + section + "] ";989for (const auto& arg : args) {990for (const auto& value : arg.second) {991std::optional<unsigned int> flags = GetArgFlags_('-' + arg.first);992if (flags) {993std::string value_str = (*flags & SENSITIVE) ? "****" : value.write();994LogInfo("%s %s%s=%s\n", prefix, section_str, arg.first, value_str);995}996}997}998}1000void ArgsManager::LogArgs() const
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.