8#ifdef ENABLE_EXTERNAL_SIGNER
9#if defined(WIN32) && !defined(__kernel_entry)
14#include <boost/process.hpp>
26#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
28#include <pthread_np.h>
39#define _POSIX_C_SOURCE 200112L
47#include <sys/resource.h>
53#pragma warning(disable:4786)
54#pragma warning(disable:4804)
55#pragma warning(disable:4805)
56#pragma warning(disable:4717)
69#ifdef HAVE_MALLOPT_ARENA_MAX
73#include <boost/algorithm/string/replace.hpp>
99 fs::path pathLockFile = directory / lockfile_name;
108 if (file) fclose(file);
109 auto lock = std::make_unique<fsbridge::FileLock>(pathLockFile);
110 if (!lock->TryLock()) {
111 return error(
"Error while attempting to lock directory %s: %s",
fs::PathToString(directory), lock->GetReason());
137 if (!file)
return false;
147 constexpr uint64_t min_disk_space = 52428800;
149 uint64_t free_bytes_available = fs::space(dir).available;
150 return free_bytes_available >= min_disk_space + additional_bytes;
153std::streampos
GetFileSize(
const char* path, std::streamsize max) {
156 return file.gcount();
176 if (strValue.empty())
178 return (LocaleIndependentAtoi<int>(strValue) != 0);
183 return arg.size() > 0 && arg[0] ==
'-' ? arg.substr(1) : arg;
204 size_t option_index = key.find(
'.');
205 if (option_index != std::string::npos) {
206 result.
section = key.substr(0, option_index);
207 key.erase(0, option_index + 1);
209 if (key.substr(0, 2) ==
"no") {
234 error =
strprintf(
"Negating of -%s is meaningless and therefore forbidden", key.
name);
239 LogPrintf(
"Warning: parsed potentially confusing double-negative -%s=%s\n", key.
name, value);
252 result = result.parent_path();
255 assert(fs::equivalent(result, path));
268 std::set<std::string> unsuitables;
273 if (m_network.empty())
return std::set<std::string> {};
278 for (
const auto& arg : m_network_only_args) {
280 unsuitables.insert(arg);
289 static const std::set<std::string> available_sections{
297 std::list<SectionInfo> unrecognized = m_config_sections;
298 unrecognized.remove_if([](
const SectionInfo& appeared){
return available_sections.find(appeared.
m_name) != available_sections.end(); });
311 m_settings.command_line_options.clear();
313 for (
int i = 1; i < argc; i++) {
314 std::string key(argv[i]);
321 if (key.substr(0, 5) ==
"-psn_")
continue;
324 if (key ==
"-")
break;
326 size_t is_index = key.find(
'=');
327 if (is_index != std::string::npos) {
328 val = key.substr(is_index + 1);
338 if (!m_accept_any_command &&
m_command.empty()) {
355 if (key.length() > 1 && key[1] ==
'-')
372 if (!value)
return false;
374 m_settings.command_line_options[keyinfo.
name].push_back(*value);
378 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
382 error =
"-includeconf cannot be used from commandline; -includeconf=" +
values.begin()->write();
392 for (
const auto& arg_map : m_available_args) {
393 const auto search = arg_map.second.find(
name);
394 if (search != arg_map.second.end()) {
395 return search->second.m_flags;
404 fs::path& path = m_cached_blocks_path;
408 if (!path.empty())
return path;
412 if (!fs::is_directory(path)) {
422 fs::create_directories(path);
423 path = StripRedundantLastElementsOfPath(path);
430 fs::path& path = net_specific ? m_cached_network_datadir_path : m_cached_datadir_path;
434 if (!path.empty())
return path;
436 std::string datadir =
GetArg(
"-datadir",
"");
437 if (!datadir.empty()) {
439 if (!fs::is_directory(path)) {
449 if (fs::create_directories(path)) {
451 fs::create_directories(path /
"wallets");
454 path = StripRedundantLastElementsOfPath(path);
463 m_cached_network_datadir_path =
fs::path();
476 if (!m_accept_any_command) {
482 ret.
args.push_back(*(it++));
489 std::vector<std::string> result;
491 result.push_back(value.isFalse() ?
"0" : value.isTrue() ?
"1" : value.get_str());
507 std::vector<std::string> errors;
531static void SaveErrors(
const std::vector<std::string> errors, std::vector<std::string>* error_out)
533 for (
const auto&
error : errors) {
535 error_out->emplace_back(
error);
550 m_settings.rw_settings.clear();
551 std::vector<std::string> read_errors;
556 for (
const auto& setting : m_settings.rw_settings) {
559 LogPrintf(
"Ignoring unknown rw_settings value %s\n", setting.first);
569 throw std::logic_error(
"Attempt to write settings file when dynamic settings are disabled.");
573 std::vector<std::string> write_errors;
627 m_settings.forced_settings[
SettingName(strArg)] = strValue;
632 Assert(cmd.find(
'=') == std::string::npos);
636 m_accept_any_command =
false;
647 size_t eq_index =
name.find(
'=');
648 if (eq_index == std::string::npos) {
649 eq_index =
name.size();
651 std::string arg_name =
name.substr(0, eq_index);
654 std::map<std::string, Arg>& arg_map = m_available_args[cat];
655 auto ret = arg_map.emplace(arg_name,
Arg{
name.substr(eq_index,
name.size() - eq_index),
help,
flags});
659 m_network_only_args.emplace(arg_name);
665 for (
const std::string&
name : names) {
672 const bool show_debug =
GetBoolArg(
"-help-debug",
false);
674 std::string usage =
"";
676 for (
const auto& arg_map : m_available_args) {
677 switch(arg_map.first) {
703 if (show_debug) usage +=
HelpMessageGroup(
"Wallet debugging/testing options:");
724 for (
const auto& arg : arg_map.second) {
727 if (arg.second.m_help_param.empty()) {
730 name = arg.first + arg.second.m_help_param;
755 return std::string(message) + std::string(
"\n\n");
758std::string
HelpMessageOpt(
const std::string &option,
const std::string &message) {
759 return std::string(
optIndent,
' ') + std::string(option) +
760 std::string(
"\n") + std::string(
msgIndent,
' ') +
769 GetModuleFileNameA(
nullptr, pszModule,
sizeof(pszModule));
771 const char* pszModule =
"bitcoin";
775 "EXCEPTION: %s \n%s \n%s in %s \n",
typeid(*pex).name(), pex->what(), pszModule, pszThread);
778 "UNKNOWN EXCEPTION \n%s in %s \n", pszModule, pszThread);
784 LogPrintf(
"\n\n************************\n%s\n", message);
785 tfm::format(std::cerr,
"\n\n************************\n%s\n", message);
795 return GetSpecialFolderPath(CSIDL_APPDATA) /
"Bitcoin";
798 char* pszHome = getenv(
"HOME");
799 if (pszHome ==
nullptr || strlen(pszHome) == 0)
805 return pathRet /
"Library/Application Support/Bitcoin";
808 return pathRet /
".bitcoin";
815 std::string datadir =
gArgs.
GetArg(
"-datadir",
"");
824static bool GetConfigOptions(std::istream& stream,
const std::string& filepath, std::string&
error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo>& sections)
827 std::string::size_type pos;
829 while (std::getline(stream, str)) {
830 bool used_hash =
false;
831 if ((pos = str.find(
'#')) != std::string::npos) {
832 str = str.substr(0, pos);
835 const static std::string pattern =
" \t\r\n";
838 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
839 const std::string section = str.substr(1, str.size() - 2);
840 sections.emplace_back(
SectionInfo{section, filepath, linenr});
842 }
else if (*str.begin() ==
'-') {
843 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
845 }
else if ((pos = str.find(
'=')) != std::string::npos) {
847 std::string value =
TrimString(str.substr(pos + 1), pattern);
848 if (used_hash &&
name.find(
"rpcpassword") != std::string::npos) {
849 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
852 options.emplace_back(
name, value);
853 if ((pos =
name.rfind(
'.')) != std::string::npos &&
prefix.length() <= pos) {
854 sections.emplace_back(
SectionInfo{
name.substr(0, pos), filepath, linenr});
858 if (str.size() >= 2 && str.substr(0, 2) ==
"no") {
859 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
872 std::vector<std::pair<std::string, std::string>> options;
876 for (
const std::pair<std::string, std::string>& option : options) {
884 m_settings.ro_config[key.
section][key.
name].push_back(*value);
886 if (ignore_invalid_keys) {
887 LogPrintf(
"Ignoring unknown configuration value %s\n", option.first);
889 error =
strprintf(
"Invalid configuration value %s", option.first);
901 m_settings.ro_config.clear();
902 m_config_sections.clear();
909 if (
IsArgSet(
"-conf") && !stream.good()) {
910 error =
strprintf(
"specified config file \"%s\" could not be opened.", confPath);
920 bool use_conf_file{
true};
923 if (
auto* includes =
util::FindKey(m_settings.command_line_options,
"includeconf")) {
926 use_conf_file =
false;
931 std::vector<std::string> conf_file_names;
933 auto add_includes = [&](
const std::string& network,
size_t skip = 0) {
934 size_t num_values = 0;
936 if (
auto* section =
util::FindKey(m_settings.ro_config, network)) {
939 conf_file_names.push_back((*
values)[i].get_str());
941 num_values =
values->size();
949 const size_t chain_includes = add_includes(chain_id);
950 const size_t default_includes = add_includes({});
952 for (
const std::string& conf_file_name : conf_file_names) {
954 if (conf_file_stream.good()) {
958 LogPrintf(
"Included configuration file %s\n", conf_file_name);
960 error =
"Failed to include configuration file " + conf_file_name;
966 conf_file_names.clear();
967 add_includes(chain_id, chain_includes);
968 add_includes({}, default_includes);
970 if (chain_id_final != chain_id) {
972 add_includes(chain_id_final);
974 for (
const std::string& conf_file_name : conf_file_names) {
975 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", conf_file_name);
991 auto get_net = [&](
const std::string& arg) {
999 const bool fRegTest = get_net(
"-regtest");
1000 const bool fSigNet = get_net(
"-signet");
1001 const bool fTestNet = get_net(
"-testnet");
1002 const bool is_chain_arg_set =
IsArgSet(
"-chain");
1004 if ((
int)is_chain_arg_set + (
int)fRegTest + (
int)fSigNet + (
int)fTestNet > 1) {
1005 throw std::runtime_error(
"Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.");
1037 const std::string&
prefix,
1038 const std::string& section,
1039 const std::map<std::string, std::vector<util::SettingsValue>>& args)
const
1041 std::string section_str = section.empty() ?
"" :
"[" + section +
"] ";
1042 for (
const auto& arg : args) {
1043 for (
const auto& value : arg.second) {
1046 std::string value_str = (*
flags &
SENSITIVE) ?
"****" : value.write();
1056 for (
const auto& section : m_settings.ro_config) {
1057 logArgsPrefix(
"Config file arg:", section.first, section.second);
1059 for (
const auto& setting : m_settings.rw_settings) {
1060 LogPrintf(
"Setting file arg: %s = %s\n", setting.first, setting.second.write());
1062 logArgsPrefix(
"Command-line arg:",
"", m_settings.command_line_options);
1068 return MoveFileExW(src.wstring().c_str(), dest.wstring().c_str(),
1069 MOVEFILE_REPLACE_EXISTING) != 0;
1071 int rc = std::rename(src.c_str(), dest.c_str());
1085 return fs::create_directories(p);
1086 }
catch (
const fs::filesystem_error&) {
1097 if (fflush(file) != 0) {
1098 LogPrintf(
"%s: fflush failed: %d\n", __func__, errno);
1102 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1103 if (FlushFileBuffers(hFile) == 0) {
1104 LogPrintf(
"%s: FlushFileBuffers failed: %d\n", __func__, GetLastError());
1107#elif defined(MAC_OSX) && defined(F_FULLFSYNC)
1108 if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) {
1109 LogPrintf(
"%s: fcntl F_FULLFSYNC failed: %d\n", __func__, errno);
1113 if (fdatasync(fileno(file)) != 0 && errno != EINVAL) {
1114 LogPrintf(
"%s: fdatasync failed: %d\n", __func__, errno);
1118 if (fsync(fileno(file)) != 0 && errno != EINVAL) {
1119 LogPrintf(
"%s: fsync failed: %d\n", __func__, errno);
1131 fsync(fileno(file));
1139 return _chsize(_fileno(file), length) == 0;
1141 return ftruncate(fileno(file), length) == 0;
1153 struct rlimit limitFD;
1154 if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) {
1155 if (limitFD.rlim_cur < (rlim_t)nMinFD) {
1156 limitFD.rlim_cur = nMinFD;
1157 if (limitFD.rlim_cur > limitFD.rlim_max)
1158 limitFD.rlim_cur = limitFD.rlim_max;
1159 setrlimit(RLIMIT_NOFILE, &limitFD);
1160 getrlimit(RLIMIT_NOFILE, &limitFD);
1162 return limitFD.rlim_cur;
1175 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file));
1176 LARGE_INTEGER nFileSize;
1177 int64_t nEndPos = (int64_t)offset + length;
1178 nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF;
1179 nFileSize.u.HighPart = nEndPos >> 32;
1180 SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN);
1181 SetEndOfFile(hFile);
1182#elif defined(MAC_OSX)
1187 fst.fst_flags = F_ALLOCATECONTIG;
1188 fst.fst_posmode = F_PEOFPOSMODE;
1190 fst.fst_length = length;
1191 fst.fst_bytesalloc = 0;
1192 if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) {
1193 fst.fst_flags = F_ALLOCATEALL;
1194 fcntl(fileno(file), F_PREALLOCATE, &fst);
1196 ftruncate(fileno(file),
static_cast<off_t
>(offset) + length);
1198 #if defined(HAVE_POSIX_FALLOCATE)
1200 off_t nEndPos = (off_t)offset + length;
1201 if (0 == posix_fallocate(fileno(file), 0, nEndPos))
return;
1205 static const char buf[65536] = {};
1206 if (fseek(file, offset, SEEK_SET)) {
1209 while (length > 0) {
1210 unsigned int now = 65536;
1213 fwrite(buf, 1, now, file);
1220fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate)
1224 if(SHGetSpecialFolderPathW(
nullptr, pszPath, nFolder, fCreate))
1229 LogPrintf(
"SHGetSpecialFolderPathW() failed, could not obtain requested path.\n");
1237 std::string escaped = arg;
1238 boost::replace_all(escaped,
"'",
"'\"'\"'");
1239 return "'" + escaped +
"'";
1244void runCommand(
const std::string& strCommand)
1246 if (strCommand.empty())
return;
1248 int nErr = ::system(strCommand.c_str());
1250 int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>().from_bytes(strCommand).c_str());
1253 LogPrintf(
"runCommand error: system(%s) returned %d\n", strCommand, nErr);
1259#ifdef ENABLE_EXTERNAL_SIGNER
1260 namespace bp = boost::process;
1263 bp::opstream stdin_stream;
1264 bp::ipstream stdout_stream;
1265 bp::ipstream stderr_stream;
1271 bp::std_out > stdout_stream,
1272 bp::std_err > stderr_stream,
1273 bp::std_in < stdin_stream
1275 if (!str_std_in.empty()) {
1276 stdin_stream << str_std_in << std::endl;
1278 stdin_stream.pipe().close();
1282 std::getline(stdout_stream, result);
1283 std::getline(stderr_stream,
error);
1286 const int n_error = c.exit_code();
1287 if (n_error)
throw std::runtime_error(
strprintf(
"RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error,
error));
1288 if (!result_json.
read(result))
throw std::runtime_error(
"Unable to parse JSON: " + result);
1292 throw std::runtime_error(
"Compiled without external signing support (required for external signing).");
1298#ifdef HAVE_MALLOPT_ARENA_MAX
1304 if (
sizeof(
void*) == 4) {
1305 mallopt(M_ARENA_MAX, 1);
1310#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
1313 }
catch (
const std::runtime_error&) {
1314 setenv(
"LC_ALL",
"C.UTF-8", 1);
1318 SetConsoleCP(CP_UTF8);
1319 SetConsoleOutputCP(CP_UTF8);
1325 std::locale loc = fs::path::imbue(std::locale::classic());
1327 fs::path::imbue(loc);
1329 fs::path::imbue(std::locale(loc,
new std::codecvt_utf8_utf16<wchar_t>()));
1338 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
1339 if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
1347 return std::thread::hardware_concurrency();
1353 std::string strCopyrightHolders = strPrefix + copyright_devs;
1356 if (copyright_devs.find(
"Bitcoin Core") == std::string::npos) {
1357 strCopyrightHolders +=
"\n" + strPrefix +
"The Bitcoin Core developers";
1359 return strCopyrightHolders;
1370 if (path.is_absolute()) {
1379 const static sched_param param{};
1380 const int rc = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m);
1382 LogPrintf(
"Failed to pthread_setschedparam: %s\n", strerror(rc));
1389WinCmdLineArgs::WinCmdLineArgs()
1391 wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1392 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t> utf8_cvt;
1393 argv =
new char*[argc];
1395 for (
int i = 0; i < argc; i++) {
1396 args[i] = utf8_cvt.to_bytes(wargv[i]);
1397 argv[i] = &*args[i].begin();
1402WinCmdLineArgs::~WinCmdLineArgs()
1407std::pair<int, char**> WinCmdLineArgs::get()
1409 return std::make_pair(argc, argv);
#define COPYRIGHT_HOLDERS_SUBSTITUTION
#define COPYRIGHT_HOLDERS
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
#define Assert(val)
Identity function.
const fs::path & GetDataDirBase() const
Get data directory path.
const std::set< std::string > GetUnsuitableSectionOnlyArgs() const
Log warnings for options in m_section_only_args when they are specified in the default section but no...
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
@ ALLOW_ANY
disable validation
@ DISALLOW_NEGATION
disallow -nofoo syntax
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
std::string GetHelpMessage() const
Get the help string.
void ClearPathCache()
Clear cached directory paths.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue > > &args) const
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
bool UseDefaultSection(const std::string &arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
Returns true if settings values from the default section should be used, depending on the current net...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
static const std::string REGTEST
static const std::string TESTNET
static const std::string SIGNET
static const std::string MAIN
Chain name strings.
const std::string & get_str() const
int64_t get_int64() const
bool read(const char *raw, size_t len)
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
fs::path GetUniquePath(const fs::path &base)
Helper function for getting a unique path.
static path system_complete(const path &p)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
FILE * fopen(const fs::path &p, const char *mode)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times,...
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
std::vector< std::string > args
If command is non-empty: Any args that followed it If command is empty: The unregistered command and ...
std::string command
The command (if one has been registered with AddCommand), or empty.
Accessor for list of settings that skips negated values when iterated over.
size_t negated() const
Number of negated values.
bool last_negated() const
True if the last value is negated.
bool error(const char *fmt, const Args &... args)
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
bilingual_str _(const char *psz)
Translation function.
static Mutex cs_dir_locks
Mutex to protect dir_locks.
bool HelpRequested(const ArgsManager &args)
static bool GetConfigOptions(std::istream &stream, const std::string &filepath, std::string &error, std::vector< std::pair< std::string, std::string > > &options, std::list< SectionInfo > §ions)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
fs::path GetDefaultDataDir()
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
static const int msgIndent
static void SaveErrors(const std::vector< std::string > errors, std::vector< std::string > *error_out)
const char *const BITCOIN_SETTINGS_FILENAME
std::string CopyrightHolders(const std::string &strPrefix)
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only)
void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name)
bool CheckDataDirOption()
static std::string FormatException(const std::exception *pex, const char *pszThread)
bool DirIsWritable(const fs::path &directory)
bool RenameOver(fs::path src, fs::path dest)
std::streampos GetFileSize(const char *path, std::streamsize max)
Get the size of a file by scanning it.
UniValue RunCommandParseJSON(const std::string &str_command, const std::string &str_std_in)
Execute a command which returns JSON, and parse the result.
void ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
static const int screenWidth
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
static std::optional< util::SettingsValue > InterpretValue(const KeyInfo &key, const std::string &value, unsigned int flags, std::string &error)
Interpret settings value based on registered flags.
void ReleaseDirectoryLocks()
Release all directory locks.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
fs::path GetConfigFile(const std::string &confPath)
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
static std::string SettingName(const std::string &arg)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
KeyInfo InterpretKey(std::string key)
Parse "name", "section.name", "noname", "section.noname" settings keys.
const int64_t nStartupTime
const char *const BITCOIN_CONF_FILENAME
bool TruncateFile(FILE *file, unsigned int length)
static std::map< std::string, std::unique_ptr< fsbridge::FileLock > > dir_locks GUARDED_BY(cs_dir_locks)
A map that contains all the currently held directory locks.
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
static const int optIndent
int GetNumCores()
Return the number of cores available on the current system.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
std::string ShellEscape(const std::string &arg)