10 #ifndef BITCOIN_UTIL_H 11 #define BITCOIN_UTIL_H 13 #if defined(HAVE_CONFIG_H) 31 #include <unordered_set> 35 #include <boost/thread/condition_variable.hpp> 50 inline std::string
_(
const char* psz)
58 template<
typename... Args>
59 bool error(
const char* fmt,
const Args&... args)
61 LogPrintf(
"ERROR: %s\n",
tfm::format(fmt, args...));
71 bool LockDirectory(
const fs::path& directory,
const std::string lockfile_name,
bool probe_only=
false);
82 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
90 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
92 void runCommand(
const std::string& strCommand);
107 return c ==
'-' || c ==
'/';
146 std::map<std::string, std::vector<std::string>> m_override_args
GUARDED_BY(
cs_args);
147 std::map<std::string, std::vector<std::string>> m_config_args
GUARDED_BY(
cs_args);
150 std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args
GUARDED_BY(
cs_args);
179 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
187 bool IsArgSet(
const std::string& strArg)
const;
205 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
214 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
const;
223 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
232 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
245 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
268 m_available_args.clear();
279 bool IsArgKnown(
const std::string& key)
const;
304 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
323 LogPrintf(
"%s thread start\n",
name);
325 LogPrintf(
"%s thread exit\n",
name);
327 catch (
const boost::thread_interrupted&)
329 LogPrintf(
"%s thread interrupt\n",
name);
332 catch (
const std::exception& e) {
358 template <
typename Tdst,
typename Tsrc>
359 inline void insert(Tdst& dst,
const Tsrc& src) {
360 dst.insert(dst.begin(), src.begin(), src.end());
362 template <
typename TsetT,
typename Tsrc>
363 inline void insert(std::set<TsetT>& dst,
const Tsrc& src) {
364 dst.insert(src.begin(), src.end());
373 std::pair<int, char**>
get();
378 std::vector<std::string> args;
384 #endif // BITCOIN_UTIL_H bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
bool HelpRequested(const ArgsManager &args)
bool FileCommit(FILE *file)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, thread wrappers, startup time.
const fs::path & GetBlocksDir(bool fNetSpecific=true)
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void WarnForSectionOnlyArgs()
Log warnings for options in m_section_only_args when they are specified in the default section but no...
bool LockDirectory(const fs::path &directory, const std::string lockfile_name, bool probe_only=false)
void SelectConfigNetwork(const std::string &network)
Select the network in use.
void RenameThread(const char *name)
void insert(Tdst &dst, const Tsrc &src)
Simplification of std insertion.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
bool IsArgKnown(const std::string &key) const
Check whether we know of this arg.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
std::string GetHelpMessage() const
Get the help string.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
const char *const BITCOIN_PID_FILENAME
fs::path GetDefaultDataDir()
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
void CreatePidFile(const fs::path &path, pid_t pid)
void TraceThread(const char *name, Callable func)
void ReleaseDirectoryLocks()
Release all directory locks.
int ScheduleBatchPriority()
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
int GetNumCores()
Return the number of cores available on the current system.
UniValue help(const JSONRPCRequest &jsonRequest)
void ClearArgs()
Clear available arguments.
const fs::path & GetDataDir(bool fNetSpecific=true)
void runCommand(const std::string &strCommand)
Arg(const std::string &help_param, const std::string &help_text, bool debug_only)
std::map< std::string, std::vector< std::string > > m_override_args GUARDED_BY(cs_args)
void SetThreadPriority(int nPriority)
fs::path GetConfigFile(const std::string &confPath)
const char *const BITCOIN_CONF_FILENAME
bool IsSwitchChar(char c)
Internal helper functions for ArgsManager.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
std::string CopyrightHolders(const std::string &strPrefix)
bool RenameOver(fs::path src, fs::path dest)
bool ReadConfigStream(std::istream &stream, std::string &error, bool ignore_invalid_keys=false)
bool error(const char *fmt, const Args &... args)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
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...
bool DirIsWritable(const fs::path &directory)
bool TruncateFile(FILE *file, unsigned int length)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific=true)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::string _(const char *psz)
Translation function.
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate a message to the native language of the user.