Inside Bitcoin
Opening the selected file…
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.
251/**252* Get data directory path with appended network identifier253*254* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned255*/256fs::path GetDataDirNet() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);258/**259* Clear cached directory paths260*/261void ClearPathCache() EXCLUSIVE_LOCKS_REQUIRED(!cs_args);263/**264* Return a vector of strings of the given argument265*266* @param strArg Argument to get (e.g. "-foo")267* @return command-line arguments268*/269std::vector<std::string> GetArgs(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);271/**272* Return true if the given argument has been manually set273*274* @param strArg Argument to get (e.g. "-foo")275* @return true if the argument has been set276*/277bool IsArgSet(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);279/**280* Return true if the argument was originally passed as a negated option,281* i.e. -nofoo.282*283* @param strArg Argument to get (e.g. "-foo")284* @return true if the argument was passed negated285*/286bool IsArgNegated(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);288/**289* Return string argument or default value290*291* @param strArg Argument to get (e.g. "-foo")292* @param strDefault (e.g. "1")293* @return command-line argument or default value294*/295std::string GetArg(const std::string& strArg, const std::string& strDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);296std::optional<std::string> GetArg(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);298/**299* Return path argument or default value300*301* @param arg Argument to get a path from (e.g., "-datadir", "-blocksdir" or "-walletdir")302* @param default_value Optional default value to return instead of the empty path.303* @return normalized path if argument is set, with redundant "." and ".."304* path components and trailing separators removed (see patharg unit test305* for examples or implementation for details). If argument is empty or not306* set, default_value is returned unchanged.307*/308fs::path GetPathArg(std::string arg, const fs::path& default_value = {}) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);310/**311* Return integer argument or default value312*313* @param strArg Argument to get (e.g. "-foo")314* @param nDefault (e.g. 1)315* @return command-line argument (0 if invalid number) or default value316*/317template <std::integral Int>318Int GetArg(const std::string& strArg, Int nDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);320template <std::integral Int>321std::optional<Int> GetArg(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);323int64_t GetIntArg(const std::string& strArg, int64_t nDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args) { return GetArg<int64_t>(strArg, nDefault); }324std::optional<int64_t> GetIntArg(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args) { return GetArg<int64_t>(strArg); }326/**327* Return boolean argument or default value328*329* @param strArg Argument to get (e.g. "-foo")330* @param fDefault (true or false)331* @return command-line argument or default value332*/333bool GetBoolArg(const std::string& strArg, bool fDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);334std::optional<bool> GetBoolArg(const std::string& strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);336/**337* Set an argument if it doesn't already have a value338*339* @param strArg Argument to set (e.g. "-foo")340* @param strValue Value (e.g. "1")341* @return true if argument gets set, false if it already had a value342*/343bool SoftSetArg(const std::string& strArg, const std::string& strValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);345/**346* Set a boolean argument if it doesn't already have a value347*348* @param strArg Argument to set (e.g. "-foo")349* @param fValue Value (e.g. false)350* @return true if argument gets set, false if it already had a value351*/352bool SoftSetBoolArg(const std::string& strArg, bool fValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);354// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already355// been set. Also called directly in testing.356void ForceSetArg(const std::string& strArg, const std::string& strValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);358/**359* Returns the appropriate chain type from the program arguments.360* @return ChainType::MAIN by default; raises runtime error if an invalid361* combination, or unknown chain is given.362*/363ChainType GetChainType() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);365/**366* Returns the appropriate chain type string from the program arguments.367* @return ChainType::MAIN string by default; raises runtime error if an368* invalid combination is given.369*/370std::string GetChainTypeString() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);372/**373* Add argument374*/375void AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);377/**378* Add command379*/380void AddCommand(const std::string& cmd, const std::string& help, std::set<std::string> options = {}) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);382/**383* Add many hidden arguments384*/385void AddHiddenArgs(const std::vector<std::string>& args) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);387/**388* Clear available arguments389*/390void ClearArgs() EXCLUSIVE_LOCKS_REQUIRED(!cs_args);392/**393* Check CLI command args394*395* @throws std::runtime_error when multiple CLI_COMMAND arguments are specified396*/397void CheckMultipleCLIArgs() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);399/**400* Get the help string401*/402std::string GetHelpMessage() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);404/**405* Return Flags for known arg.406* Return default flags for unknown arg.407*/408std::optional<unsigned int> GetArgFlags(const std::string& name) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);410/**411* Set default flags to return for an unknown arg.412*/413void SetDefaultFlags(std::optional<unsigned int>) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);415/**416* Get settings file path, or return false if read-write settings were417* disabled with -nosettings.418*/419bool GetSettingsPath(fs::path* filepath = nullptr, bool temp = false, bool backup = false) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);421/**422* Read settings file. Push errors to vector, or log them if null.423*/424bool ReadSettingsFile(std::vector<std::string>* errors = nullptr) EXCLUSIVE_LOCKS_REQUIRED(!cs_args);426/**427* Write settings file or backup settings file. Push errors to vector, or428* log them if null.429*/430bool WriteSettingsFile(std::vector<std::string>* errors = nullptr, bool backup = false) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);432/**433* Get current setting from config file or read/write settings file,434* ignoring nonpersistent command line or forced settings values.435*/436common::SettingsValue GetPersistentSetting(const std::string& name) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);438/**439* Access settings with lock held.440*/441template <typename Fn>442void LockSettings(Fn&& fn) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)443{444LOCK(cs_args);445fn(m_settings);446}448/**449* Log the config file options and the command line arguments,450* useful for troubleshooting.451*/452void LogArgs() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);454private:455// Internal helpers, for use by callers that already hold `cs_args`.456common::SettingsValue GetSetting_(const std::string& arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);457std::optional<unsigned int> GetArgFlags_(const std::string& name) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);458fs::path GetPathArg_(std::string arg, const fs::path& default_value = {}) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);460/**461* Get data directory path462*463* @param net_specific Append network identifier to the returned path464* @return Absolute path on success, otherwise an empty path when a non-directory path would be returned465*/466fs::path GetDataDir(bool net_specific) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);468/**469* Return -regtest/-signet/-testnet/-testnet4/-chain= setting as a ChainType enum if a470* recognized chain type was set, or as a string if an unrecognized chain471* name was set. Raise an exception if an invalid combination of flags was472* provided.473*/474std::variant<ChainType, std::string> GetChainArg() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args);476// Helper function for LogArgs().477void logArgsPrefix(478const std::string& prefix,479const std::string& section,480const std::map<std::string, std::vector<common::SettingsValue>>& args) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);481};483extern ArgsManager gArgs;485/**486* @return true if help has been requested via a command-line arg487*/488bool HelpRequested(const ArgsManager& args);490/** Add help options to the args manager */491void SetupHelpOptions(ArgsManager& args);493extern const std::vector<std::string> TEST_OPTIONS_DOC;495/** Checks if a particular test option is present in -test command-line arg options */496bool HasTestOption(const ArgsManager& args, const std::string& test_option);498/**499* Format a string to be used as group of options in help messages500*
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.