diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -23,45 +23,55 @@ static const int64_t DEFAULT_PLOT_WIDTH = 1024; static const int64_t DEFAULT_PLOT_HEIGHT = 768; +static void SetupBenchArgs() { + gArgs.AddArg("-?", _("Print this help message and exit"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-list", + _("List benchmarks without executing them. Can be combined " + "with -scaling and -filter"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-evals=", + strprintf( + _("Number of measurement evaluations to perform. (default: %u)"), + DEFAULT_BENCH_EVALUATIONS), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-filter=", + strprintf(_("Regular expression filter to select benchmark by " + "name (default: %s)"), + DEFAULT_BENCH_FILTER), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-scaling=", + strprintf(_("Scaling factor for benchmark's runtime (default: %u)"), + DEFAULT_BENCH_SCALING), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-printer=(console|plot)", + strprintf(_("Choose printer format. console: print data to console. " + "plot: Print results as HTML graph (default: %s)"), + DEFAULT_BENCH_PRINTER), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-plot-plotlyurl=", + strprintf(_("URL to use for plotly.js (default: %s)"), + DEFAULT_PLOT_PLOTLYURL), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-plot-width=", + strprintf(_("Plot width in pixel (default: %u)"), DEFAULT_PLOT_WIDTH), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-plot-height=", + strprintf(_("Plot height in pixel (default: %u)"), DEFAULT_PLOT_HEIGHT), + false, OptionsCategory::OPTIONS); +} + int main(int argc, char **argv) { + SetupBenchArgs(); gArgs.ParseParameters(argc, argv); if (HelpRequested(gArgs)) { - std::cout - << HelpMessageGroup(_("Options:")) - << HelpMessageOpt("-?", _("Print this help message and exit")) - << HelpMessageOpt("-list", - _("List benchmarks without executing them. Can " - "be combined with -scaling and -filter")) - << HelpMessageOpt("-evals=", - strprintf(_("Number of measurement evaluations " - "to perform. (default: %u)"), - DEFAULT_BENCH_EVALUATIONS)) - << HelpMessageOpt("-filter=", - strprintf(_("Regular expression filter to select " - "benchmark by name (default: %s)"), - DEFAULT_BENCH_FILTER)) - << HelpMessageOpt("-scaling=", - strprintf(_("Scaling factor for benchmark's " - "runtime (default: %u)"), - DEFAULT_BENCH_SCALING)) - << HelpMessageOpt( - "-printer=(console|plot)", - strprintf(_("Choose printer format. console: print data to " - "console. plot: Print results as HTML graph " - "(default: %s)"), - DEFAULT_BENCH_PRINTER)) - << HelpMessageOpt( - "-plot-plotlyurl=", - strprintf(_("URL to use for plotly.js (default: %s)"), - DEFAULT_PLOT_PLOTLYURL)) - << HelpMessageOpt("-plot-width=", - strprintf(_("Plot width in pixel (default: %u)"), - DEFAULT_PLOT_WIDTH)) - << HelpMessageOpt("-plot-height=", - strprintf(_("Plot height in pixel (default: %u)"), - DEFAULT_PLOT_HEIGHT)); - + std::cout << gArgs.GetHelpMessage(); return 0; } diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -30,66 +30,72 @@ static const bool DEFAULT_NAMED = false; static const int CONTINUE_EXECUTION = -1; -std::string HelpMessageCli() { +static void SetupCliArgs() { const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); - std::string strUsage; - strUsage += HelpMessageGroup(_("Options:")); - strUsage += HelpMessageOpt("-?", _("This help message")); - strUsage += HelpMessageOpt( - "-conf=", strprintf(_("Specify configuration file (default: %s)"), - BITCOIN_CONF_FILENAME)); - strUsage += HelpMessageOpt("-datadir=", _("Specify data directory")); - strUsage += HelpMessageOpt( + + gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS); + gArgs.AddArg("-conf=", + strprintf(_("Specify configuration file (default: %s)"), + BITCOIN_CONF_FILENAME), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-datadir=", _("Specify data directory"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg( "-getinfo", _("Get general information from the remote server. Note that unlike " "server-side RPC calls, the results of -getinfo is the result of " "multiple non-atomic requests. Some entries in the result may " "represent results from different states (e.g. wallet balance may be " - "as of a different block from the chain state reported)")); - AppendParamsHelpMessages(strUsage); - strUsage += HelpMessageOpt( + "as of a different block from the chain state reported)"), + false, OptionsCategory::OPTIONS); + SetupChainParamsBaseOptions(); + gArgs.AddArg( "-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), - DEFAULT_NAMED)); - strUsage += HelpMessageOpt( + DEFAULT_NAMED), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-rpcconnect=", strprintf(_("Send commands to node running on (default: %s)"), - DEFAULT_RPCCONNECT)); - strUsage += HelpMessageOpt( + DEFAULT_RPCCONNECT), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-rpcport=", strprintf( _("Connect to JSON-RPC on (default: %u or testnet: %u)"), - defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort())); - strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start")); - strUsage += HelpMessageOpt("-rpcuser=", - _("Username for JSON-RPC connections")); - strUsage += HelpMessageOpt("-rpcpassword=", - _("Password for JSON-RPC connections")); - strUsage += - HelpMessageOpt("-rpcclienttimeout=", - strprintf(_("Timeout in seconds during HTTP requests, " - "or 0 for no timeout. (default: %d)"), - DEFAULT_HTTP_CLIENT_TIMEOUT)); - - strUsage += HelpMessageOpt( + defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-rpcwait", _("Wait for RPC server to start"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-rpcuser=", _("Username for JSON-RPC connections"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-rpcpassword=", _("Password for JSON-RPC connections"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-rpcclienttimeout=", + strprintf(_("Timeout in seconds during HTTP requests, or 0 " + "for no timeout. (default: %d)"), + DEFAULT_HTTP_CLIENT_TIMEOUT), + false, OptionsCategory::OPTIONS); + + gArgs.AddArg( "-stdinrpcpass", - strprintf(_("Read RPC password from standard input as a single line. " + strprintf(_("Read RPC password from standard input as a single line. " "When combined with -stdin, the first line from standard " - "input is used for the RPC password."))); - strUsage += HelpMessageOpt( - "-stdin", _("Read extra arguments from standard input, one per line " - "until EOF/Ctrl-D (recommended for sensitive information " - "such as passphrases)")); - strUsage += HelpMessageOpt( - "-rpcwallet=", - _("Send RPC for non-default wallet on RPC server (argument is wallet " - "filename in bitcoind directory, required if bitcoind/-Qt runs with " - "multiple wallets)")); - - return strUsage; + "input is used for the RPC password.")), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-stdin", + _("Read extra arguments from standard input, one per line " + "until EOF/Ctrl-D (recommended for sensitive information " + "such as passphrases)"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-rpcwallet=", + _("Send RPC for non-default wallet on RPC server (argument is " + "wallet filename in bitcoind directory, required if " + "bitcoind/-Qt runs with multiple wallets)"), + false, OptionsCategory::OPTIONS); } ////////////////////////////////////////////////////////////////////////////// @@ -115,6 +121,7 @@ // // Parameters // + SetupCliArgs(); gArgs.ParseParameters(argc, argv); if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { std::string strUsage = @@ -131,7 +138,7 @@ "or: bitcoin-cli [options] help Get " "help for a command\n"; - strUsage += "\n" + HelpMessageCli(); + strUsage += "\n" + gArgs.GetHelpMessage(); } fprintf(stdout, "%s", strUsage.c_str()); diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -32,6 +32,67 @@ static std::map registers; static const int CONTINUE_EXECUTION = -1; +static void SetupBitcoinTxArgs() { + gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS); + gArgs.AddArg("-create", _("Create new, empty TX."), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-json", _("Select JSON output"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-txid", + _("Output only the hex-encoded transaction id of the " + "resultant transaction."), + false, OptionsCategory::OPTIONS); + SetupChainParamsBaseOptions(); + + gArgs.AddArg("delin=N", _("Delete input N from TX"), false, + OptionsCategory::COMMANDS); + gArgs.AddArg("delout=N", _("Delete output N from TX"), false, + OptionsCategory::COMMANDS); + gArgs.AddArg("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"), false, + OptionsCategory::COMMANDS); + gArgs.AddArg("locktime=N", _("Set TX lock time to N"), false, + OptionsCategory::COMMANDS); + gArgs.AddArg("nversion=N", _("Set TX version to N"), false, + OptionsCategory::COMMANDS); + gArgs.AddArg("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"), + false, OptionsCategory::COMMANDS); + gArgs.AddArg("outpubkey=VALUE:PUBKEY[:FLAGS]", + _("Add pay-to-pubkey output to TX") + ". " + + _("Optionally add the \"S\" flag to wrap the output in a " + "pay-to-script-hash."), + false, OptionsCategory::COMMANDS); + gArgs.AddArg("outdata=[VALUE:]DATA", _("Add data-based output to TX"), + false, OptionsCategory::COMMANDS); + gArgs.AddArg("outscript=VALUE:SCRIPT[:FLAGS]", + _("Add raw script output to TX") + ". " + + _("Optionally add the \"S\" flag to wrap the output in a " + "pay-to-script-hash."), + false, OptionsCategory::COMMANDS); + gArgs.AddArg( + "outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", + _("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = " + "PUBKEYS") + + ". " + + _("Optionally add the \"S\" flag to wrap the output in a " + "pay-to-script-hash."), + false, OptionsCategory::COMMANDS); + gArgs.AddArg("sign=SIGHASH-FLAGS", + _("Add zero or more signatures to transaction") + ". " + + _("This command requires JSON registers:") + + _("prevtxs=JSON object") + ", " + + _("privatekeys=JSON object") + ". " + + _("See signrawtransaction docs for format of sighash " + "flags, JSON objects."), + false, OptionsCategory::COMMANDS); + + gArgs.AddArg("load=NAME:FILENAME", + _("Load JSON file FILENAME into register NAME"), false, + OptionsCategory::REGISTER_COMMANDS); + gArgs.AddArg("set=NAME:JSON-STRING", + _("Set register NAME to given JSON-STRING"), false, + OptionsCategory::REGISTER_COMMANDS); +} + // // This function returns either one of EXIT_ codes when it's expected to stop // the process or CONTINUE_EXECUTION when it's expected to continue further. @@ -40,6 +101,7 @@ // // Parameters // + SetupBitcoinTxArgs(); gArgs.ParseParameters(argc, argv); // Check for -testnet or -regtest parameter (Params() calls are only valid @@ -64,63 +126,7 @@ "hex-encoded bitcoin transaction\n" + "\n"; - fprintf(stdout, "%s", strUsage.c_str()); - - strUsage = HelpMessageGroup(_("Options:")); - strUsage += HelpMessageOpt("-?", _("This help message")); - strUsage += HelpMessageOpt("-create", _("Create new, empty TX.")); - strUsage += HelpMessageOpt("-json", _("Select JSON output")); - strUsage += - HelpMessageOpt("-txid", _("Output only the hex-encoded transaction " - "id of the resultant transaction.")); - AppendParamsHelpMessages(strUsage); - - fprintf(stdout, "%s", strUsage.c_str()); - - strUsage = HelpMessageGroup(_("Commands:")); - strUsage += HelpMessageOpt("delin=N", _("Delete input N from TX")); - strUsage += HelpMessageOpt("delout=N", _("Delete output N from TX")); - strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", - _("Add input to TX")); - strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N")); - strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N")); - strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", - _("Add address-based output to TX")); - strUsage += - HelpMessageOpt("outpubkey=VALUE:PUBKEY[:FLAGS]", - _("Add pay-to-pubkey output to TX") + ". " + - _("Optionally add the \"S\" flag to wrap the " - "output in a pay-to-script-hash.")); - strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", - _("Add data-based output to TX")); - strUsage += - HelpMessageOpt("outscript=VALUE:SCRIPT[:FLAGS]", - _("Add raw script output to TX") + ". " + - _("Optionally add the \"S\" flag to wrap the " - "output in a pay-to-script-hash.")); - strUsage += HelpMessageOpt( - "outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", - _("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = " - "PUBKEYS") + - ". " + - _("Optionally add the \"S\" flag to wrap the output in a " - "pay-to-script-hash.")); - strUsage += HelpMessageOpt( - "sign=SIGHASH-FLAGS", - _("Add zero or more signatures to transaction") + ". " + - _("This command requires JSON registers:") + - _("prevtxs=JSON object") + ", " + _("privatekeys=JSON object") + - ". " + - _("See signrawtransaction docs for format of sighash flags, " - "JSON objects.")); - fprintf(stdout, "%s", strUsage.c_str()); - - strUsage = HelpMessageGroup(_("Register Commands:")); - strUsage += - HelpMessageOpt("load=NAME:FILENAME", - _("Load JSON file FILENAME into register NAME")); - strUsage += HelpMessageOpt("set=NAME:JSON-STRING", - _("Set register NAME to given JSON-STRING")); + strUsage += gArgs.GetHelpMessage(); fprintf(stdout, "%s", strUsage.c_str()); if (argc < 2) { diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,6 +70,12 @@ // // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's // main() + SetupServerArgs(); +#if HAVE_DECL_DAEMON + gArgs.AddArg("-daemon", + _("Run in the background as a daemon and accept commands"), + false, OptionsCategory::OPTIONS); +#endif gArgs.ParseParameters(argc, argv); // Process help and version before taking care about datadir @@ -83,7 +89,7 @@ strUsage += "\nUsage: bitcoind [options] " "Start " PACKAGE_NAME " Daemon\n"; - strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND); + strUsage += "\n" + gArgs.GetHelpMessage(); } fprintf(stdout, "%s", strUsage.c_str()); diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -40,10 +40,9 @@ CreateBaseChainParams(const std::string &chain); /** - * Append the help messages for the chainparams options to the - * parameter string. + * Set the arguments for chainparams. */ -void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp = true); +void SetupChainParamsBaseOptions(); /** * Return the currently selected parameters. This won't change after app diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -14,16 +14,14 @@ const std::string CBaseChainParams::TESTNET = "test"; const std::string CBaseChainParams::REGTEST = "regtest"; -void AppendParamsHelpMessages(std::string &strUsage, bool debugHelp) { - strUsage += HelpMessageGroup(_("Chain selection options:")); - strUsage += HelpMessageOpt("-testnet", _("Use the test chain")); - if (debugHelp) { - strUsage += HelpMessageOpt( - "-regtest", "Enter regression test mode, which uses a special " - "chain in which blocks can be solved instantly. " - "This is intended for regression testing tools and app " - "development."); - } +void SetupChainParamsBaseOptions() { + gArgs.AddArg("-regtest", + "Enter regression test mode, which uses a special chain in " + "which blocks can be solved instantly. This is intended for " + "regression testing tools and app development.", + true, OptionsCategory::CHAINPARAMS); + gArgs.AddArg("-testnet", _("Use the test chain"), false, + OptionsCategory::CHAINPARAMS); } /** diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -7,6 +7,8 @@ #ifndef BITCOIN_INIT_H #define BITCOIN_INIT_H +#include + #include #include @@ -73,11 +75,11 @@ bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor); -/** The help message mode determines what help message to show */ -enum class HelpMessageMode { BITCOIND, BITCOIN_QT }; +/** + * Setup the arguments for gArgs. + */ +void SetupServerArgs(); -/** Help for options shared between UI and daemon (for -help) */ -std::string HelpMessage(HelpMessageMode mode); /** Returns licensing information (for -version) */ std::string LicenseInfo(); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -73,9 +73,7 @@ #if !(ENABLE_WALLET) class DummyWalletInit : public WalletInitInterface { public: - std::string GetHelpString(bool showDebug) const override { - return std::string{}; - } + void AddWalletOptions() const override {} bool ParameterInteraction() const override { return true; } void RegisterRPC(CRPCTable &) const override {} bool Verify(const CChainParams &chainParams) const override { return true; } @@ -313,7 +311,7 @@ LogPrint(BCLog::RPC, "RPC stopped.\n"); } -std::string HelpMessage(HelpMessageMode mode) { +void SetupServerArgs() { const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); const auto testnetBaseParams = @@ -321,133 +319,133 @@ const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN); const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET); - const bool showDebug = gArgs.GetBoolArg("-help-debug", false); + // Set all of the args and their help // When adding new options to the categories, please keep and ensure // alphabetical ordering. Do not translate _(...) -help-debug options, Many // technical terms, and only a very small audience, so is unnecessary stress // to translators. - std::string strUsage = HelpMessageGroup(_("Options:")); - strUsage += HelpMessageOpt("-?", _("Print this help message and exit")); - strUsage += HelpMessageOpt("-version", _("Print version and exit")); - strUsage += HelpMessageOpt( - "-alertnotify=", - _("Execute command when a relevant alert is received or we see a " - "really long fork (%s in cmd is replaced by message)")); - strUsage += HelpMessageOpt( - "-blocksdir=", - _("Specify blocks directory (default: /blocks)")); - strUsage += HelpMessageOpt("-blocknotify=", - _("Execute command when the best block changes " - "(%s in cmd is replaced by block hash)")); - if (showDebug) { - strUsage += HelpMessageOpt( - "-blocksonly", - strprintf( - _("Whether to operate in a blocks only mode (default: %d)"), - DEFAULT_BLOCKSONLY)); - } - strUsage += HelpMessageOpt( + gArgs.AddArg("-?", _("Print this help message and exit"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-version", _("Print version and exit"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg("-alertnotify=", + _("Execute command when a relevant alert is received or we " + "see a really long fork (%s in cmd is replaced by message)"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-blocksdir=", + _("Specify blocks directory (default: /blocks)"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-blocknotify=", + _("Execute command when the best block changes (%s in cmd is " + "replaced by block hash)"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-blocksonly", + strprintf(_("Whether to operate in a blocks only mode (default: %d)"), + DEFAULT_BLOCKSONLY), + true, OptionsCategory::OPTIONS); + gArgs.AddArg( "-assumevalid=", strprintf( _("If this block is in the chain assume that it and its ancestors " "are valid and potentially skip their script verification (0 to " "verify all, default: %s, testnet: %s)"), defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), - testnetChainParams->GetConsensus().defaultAssumeValid.GetHex())); - strUsage += HelpMessageOpt( - "-conf=", strprintf(_("Specify configuration file (default: %s)"), - BITCOIN_CONF_FILENAME)); - if (mode == HelpMessageMode::BITCOIND) { -#if HAVE_DECL_DAEMON - strUsage += HelpMessageOpt( - "-daemon", - _("Run in the background as a daemon and accept commands")); -#endif - } - strUsage += HelpMessageOpt("-datadir=", _("Specify data directory")); - if (showDebug) { - strUsage += HelpMessageOpt( - "-dbbatchsize", - strprintf( - "Maximum database write batch size in bytes (default: %u)", - nDefaultDbBatchSize)); - } - strUsage += HelpMessageOpt( + testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-conf=", + strprintf(_("Specify configuration file (default: %s)"), + BITCOIN_CONF_FILENAME), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-datadir=", _("Specify data directory"), false, + OptionsCategory::OPTIONS); + gArgs.AddArg( + "-dbbatchsize", + strprintf("Maximum database write batch size in bytes (default: %u)", + nDefaultDbBatchSize), + true, OptionsCategory::OPTIONS); + gArgs.AddArg( "-dbcache=", strprintf( _("Set database cache size in megabytes (%d to %d, default: %d)"), - nMinDbCache, nMaxDbCache, nDefaultDbCache)); - if (showDebug) { - strUsage += HelpMessageOpt( - "-feefilter", strprintf("Tell other nodes to filter invs to us by " - "our mempool min fee (default: %d)", - DEFAULT_FEEFILTER)); - } - strUsage += HelpMessageOpt( - "-finalizationdelay=", - strprintf("Set the minimum amount of time to wait between a " - "block header reception and the block finalization. " - "Unit is seconds (default: %d)", - DEFAULT_MIN_FINALIZATION_DELAY)); - strUsage += HelpMessageOpt( + nMinDbCache, nMaxDbCache, nDefaultDbCache), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-feefilter", + strprintf("Tell other nodes to filter invs to us by " + "our mempool min fee (default: %d)", + DEFAULT_FEEFILTER), + true, OptionsCategory::OPTIONS); + gArgs.AddArg("-finalizationdelay=", + strprintf("Set the minimum amount of time to wait between a " + "block header reception and the block finalization. " + "Unit is seconds (default: %d)", + DEFAULT_MIN_FINALIZATION_DELAY), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-maxreorgdepth=", strprintf("Configure at what depth blocks are considered final " "(default: %d). Use -1 to disable.", - DEFAULT_MAX_REORG_DEPTH)); - strUsage += HelpMessageOpt( - "-loadblock=", - _("Imports blocks from external blk000??.dat file on startup")); - strUsage += HelpMessageOpt( + DEFAULT_MAX_REORG_DEPTH), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-loadblock=", + _("Imports blocks from external blk000??.dat file on startup"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-debuglogfile=", strprintf( _("Specify location of debug log file: this can be an absolute " "path or a path relative to the data directory (default: %s)"), - DEFAULT_DEBUGLOGFILE)); - strUsage += HelpMessageOpt( - "-maxorphantx=", strprintf(_("Keep at most unconnectable " - "transactions in memory (default: %u)"), - DEFAULT_MAX_ORPHAN_TRANSACTIONS)); - strUsage += HelpMessageOpt("-maxmempool=", - strprintf(_("Keep the transaction memory pool " - "below megabytes (default: %u)"), - DEFAULT_MAX_MEMPOOL_SIZE)); - strUsage += - HelpMessageOpt("-mempoolexpiry=", - strprintf(_("Do not keep transactions in the mempool " - "longer than hours (default: %u)"), - DEFAULT_MEMPOOL_EXPIRY)); - if (showDebug) { - strUsage += HelpMessageOpt( - "-minimumchainwork=", - strprintf( - "Minimum work assumed to exist on a valid chain in hex " - "(default: %s, testnet: %s)", - defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), - testnetChainParams->GetConsensus().nMinimumChainWork.GetHex())); - } - strUsage += - HelpMessageOpt("-persistmempool", - strprintf(_("Whether to save the mempool on shutdown " - "and load on restart (default: %u)"), - DEFAULT_PERSIST_MEMPOOL)); - strUsage += HelpMessageOpt( + DEFAULT_DEBUGLOGFILE), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-maxorphantx=", + strprintf(_("Keep at most unconnectable " + "transactions in memory (default: %u)"), + DEFAULT_MAX_ORPHAN_TRANSACTIONS), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-maxmempool=", + strprintf(_("Keep the transaction memory pool " + "below megabytes (default: %u)"), + DEFAULT_MAX_MEMPOOL_SIZE), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-mempoolexpiry=", + strprintf(_("Do not keep transactions in the mempool " + "longer than hours (default: %u)"), + DEFAULT_MEMPOOL_EXPIRY), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( + "-minimumchainwork=", + strprintf( + "Minimum work assumed to exist on a valid chain in hex " + "(default: %s, testnet: %s)", + defaultChainParams->GetConsensus().nMinimumChainWork.GetHex(), + testnetChainParams->GetConsensus().nMinimumChainWork.GetHex()), + true, OptionsCategory::OPTIONS); + gArgs.AddArg("-persistmempool", + strprintf(_("Whether to save the mempool on shutdown " + "and load on restart (default: %u)"), + DEFAULT_PERSIST_MEMPOOL), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-blockreconstructionextratxn=", strprintf(_("Extra transactions to keep in memory for compact block " "reconstructions (default: %u)"), - DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN)); - strUsage += HelpMessageOpt( + DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), + false, OptionsCategory::OPTIONS); + gArgs.AddArg( "-par=", strprintf(_("Set the number of script verification threads (%u to %d, " "0 = auto, <0 = leave that many cores free, default: %d)"), -GetNumCores(), MAX_SCRIPTCHECK_THREADS, - DEFAULT_SCRIPTCHECK_THREADS)); + DEFAULT_SCRIPTCHECK_THREADS), + false, OptionsCategory::OPTIONS); #ifndef WIN32 - strUsage += HelpMessageOpt( + gArgs.AddArg( "-pid=", - strprintf(_("Specify pid file (default: %s)"), BITCOIN_PID_FILENAME)); + strprintf(_("Specify pid file (default: %s)"), BITCOIN_PID_FILENAME), + false, OptionsCategory::OPTIONS); #endif - strUsage += HelpMessageOpt( + gArgs.AddArg( "-prune=", strprintf( _("Reduce storage requirements by enabling pruning (deleting) of " @@ -460,461 +458,511 @@ "(default: 0 = disable pruning blocks, 1 = allow manual pruning " "via RPC, >%u = automatically prune block files to stay under " "the specified target size in MiB)"), - MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)); - strUsage += HelpMessageOpt( - "-reindex-chainstate", - _("Rebuild chain state from the currently indexed blocks")); - strUsage += - HelpMessageOpt("-reindex", _("Rebuild chain state and block index from " - "the blk*.dat files on disk")); + MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-reindex-chainstate", + _("Rebuild chain state from the currently indexed blocks"), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-reindex", + _("Rebuild chain state and block index from the blk*.dat " + "files on disk"), + false, OptionsCategory::OPTIONS); #ifndef WIN32 - strUsage += HelpMessageOpt( + gArgs.AddArg( "-sysperms", _("Create new files with system default permissions, instead of umask " - "077 (only effective with disabled wallet functionality)")); + "077 (only effective with disabled wallet functionality)"), + false, OptionsCategory::OPTIONS); #endif - strUsage += HelpMessageOpt( - "-txindex", strprintf(_("Maintain a full transaction index, used by " - "the getrawtransaction rpc call (default: %d)"), - DEFAULT_TXINDEX)); - strUsage += HelpMessageOpt( - "-usecashaddr", _("Use Cash Address for destination encoding instead " - "of base58 (activate by default on Jan, 14)")); - - strUsage += HelpMessageGroup(_("Connection options:")); - strUsage += HelpMessageOpt( + gArgs.AddArg("-txindex", + strprintf(_("Maintain a full transaction index, used by the " + "getrawtransaction rpc call (default: %d)"), + DEFAULT_TXINDEX), + false, OptionsCategory::OPTIONS); + gArgs.AddArg("-usecashaddr", + _("Use Cash Address for destination encoding instead " + "of base58 (activate by default on Jan, 14)"), + false, OptionsCategory::OPTIONS); + + gArgs.AddArg( "-addnode=", _("Add a node to connect to and attempt to keep the connection open " - "(see the `addnode` RPC command help for more info)")); - strUsage += HelpMessageOpt( + "(see the `addnode` RPC command help for more info)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-banscore=", strprintf( _("Threshold for disconnecting misbehaving peers (default: %u)"), - DEFAULT_BANSCORE_THRESHOLD)); - strUsage += HelpMessageOpt( - "-bantime=", strprintf(_("Number of seconds to keep misbehaving " - "peers from reconnecting (default: %u)"), - DEFAULT_MISBEHAVING_BANTIME)); - strUsage += HelpMessageOpt("-bind=", - _("Bind to given address and always listen on " - "it. Use [host]:port notation for IPv6")); - strUsage += HelpMessageOpt( - "-connect=", _("Connect only to the specified node(s); -connect=0 " - "disables automatic connections (the rules for this " - "peer are the same as for -addnode)")); - strUsage += HelpMessageOpt("-discover", - _("Discover own IP addresses (default: 1 when " - "listening and no -externalip or -proxy)")); - strUsage += HelpMessageOpt( - "-dns", _("Allow DNS lookups for -addnode, -seednode and -connect") + - " " + strprintf(_("(default: %d)"), DEFAULT_NAME_LOOKUP)); - strUsage += HelpMessageOpt( - "-dnsseed", _("Query for peer addresses via DNS lookup, if low on " - "addresses (default: 1 unless -connect/-noconnect)")); - strUsage += HelpMessageOpt("-externalip=", - _("Specify your own public address")); - strUsage += HelpMessageOpt( + DEFAULT_BANSCORE_THRESHOLD), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-bantime=", + strprintf(_("Number of seconds to keep misbehaving peers from " + "reconnecting (default: %u)"), + DEFAULT_MISBEHAVING_BANTIME), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-bind=", + _("Bind to given address and always listen on it. Use " + "[host]:port notation for IPv6"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-connect=", + _("Connect only to the specified node(s); -connect=0 disables " + "automatic connections (the rules for this peer are the " + "same as for -addnode)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-discover", + _("Discover own IP addresses (default: 1 when listening and " + "no -externalip or -proxy)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-dns", + _("Allow DNS lookups for -addnode, -seednode and -connect") + + " " + strprintf(_("(default: %d)"), DEFAULT_NAME_LOOKUP), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-dnsseed", + _("Query for peer addresses via DNS lookup, if low on " + "addresses (default: 1 unless -connect/-noconnect)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-externalip=", _("Specify your own public address"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-forcednsseed", strprintf( _("Always query for peer addresses via DNS lookup (default: %d)"), - DEFAULT_FORCEDNSSEED)); - strUsage += - HelpMessageOpt("-listen", _("Accept connections from outside (default: " - "1 if no -proxy or -connect/-noconnect)")); - strUsage += HelpMessageOpt( + DEFAULT_FORCEDNSSEED), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-listen", + _("Accept connections from outside (default: 1 if no -proxy " + "or -connect/-noconnect)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-listenonion", strprintf(_("Automatically create Tor hidden service (default: %d)"), - DEFAULT_LISTEN_ONION)); - strUsage += HelpMessageOpt( + DEFAULT_LISTEN_ONION), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-maxconnections=", strprintf(_("Maintain at most connections to peers (default: %u)"), - DEFAULT_MAX_PEER_CONNECTIONS)); - strUsage += - HelpMessageOpt("-maxreceivebuffer=", - strprintf(_("Maximum per-connection receive buffer, " - "*1000 bytes (default: %u)"), - DEFAULT_MAXRECEIVEBUFFER)); - strUsage += HelpMessageOpt( - "-maxsendbuffer=", strprintf(_("Maximum per-connection send buffer, " - "*1000 bytes (default: %u)"), - DEFAULT_MAXSENDBUFFER)); - strUsage += HelpMessageOpt( + DEFAULT_MAX_PEER_CONNECTIONS), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-maxreceivebuffer=", + strprintf(_("Maximum per-connection receive buffer, *1000 " + "bytes (default: %u)"), + DEFAULT_MAXRECEIVEBUFFER), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-maxsendbuffer=", + strprintf(_("Maximum per-connection send buffer, *1000 " + "bytes (default: %u)"), + DEFAULT_MAXSENDBUFFER), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-maxtimeadjustment", strprintf(_("Maximum allowed median peer time offset adjustment. Local " "perspective of time may be influenced by peers forward or " "backward by this amount. (default: %u seconds)"), - DEFAULT_MAX_TIME_ADJUSTMENT)); - strUsage += - HelpMessageOpt("-onion=", - strprintf(_("Use separate SOCKS5 proxy to reach peers " - "via Tor hidden services (default: %s)"), - "-proxy")); - strUsage += HelpMessageOpt( + DEFAULT_MAX_TIME_ADJUSTMENT), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-onion=", + strprintf(_("Use separate SOCKS5 proxy to reach peers via Tor " + "hidden services (default: %s)"), + "-proxy"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-onlynet=", - _("Only connect to nodes in network (ipv4, ipv6 or onion)")); - strUsage += - HelpMessageOpt("-permitbaremultisig", - strprintf(_("Relay non-P2SH multisig (default: %d)"), - DEFAULT_PERMIT_BAREMULTISIG)); - strUsage += HelpMessageOpt( - "-peerbloomfilters", - strprintf(_("Support filtering of blocks and transaction with bloom " - "filters (default: %d)"), - DEFAULT_PEERBLOOMFILTERS)); - strUsage += HelpMessageOpt( + _("Only connect to nodes in network (ipv4, ipv6 or onion)"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-permitbaremultisig", + strprintf(_("Relay non-P2SH multisig (default: %d)"), + DEFAULT_PERMIT_BAREMULTISIG), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-peerbloomfilters", + strprintf(_("Support filtering of blocks and transaction with " + "bloom filters (default: %d)"), + DEFAULT_PEERBLOOMFILTERS), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-port=", strprintf( _("Listen for connections on (default: %u or testnet: %u)"), defaultChainParams->GetDefaultPort(), - testnetChainParams->GetDefaultPort())); - strUsage += - HelpMessageOpt("-proxy=", _("Connect through SOCKS5 proxy")); - strUsage += HelpMessageOpt( + testnetChainParams->GetDefaultPort()), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-proxy=", _("Connect through SOCKS5 proxy"), false, + OptionsCategory::CONNECTION); + gArgs.AddArg( "-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This " "enables Tor stream isolation (default: %d)"), - DEFAULT_PROXYRANDOMIZE)); - strUsage += HelpMessageOpt( + DEFAULT_PROXYRANDOMIZE), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-seednode=", - _("Connect to a node to retrieve peer addresses, and disconnect")); - strUsage += HelpMessageOpt( - "-timeout=", strprintf(_("Specify connection timeout in " - "milliseconds (minimum: 1, default: %d)"), - DEFAULT_CONNECT_TIMEOUT)); - strUsage += HelpMessageOpt("-torcontrol=:", - strprintf(_("Tor control port to use if onion " - "listening enabled (default: %s)"), - DEFAULT_TOR_CONTROL)); - strUsage += HelpMessageOpt("-torpassword=", - _("Tor control port password (default: empty)")); + _("Connect to a node to retrieve peer addresses, and disconnect"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-timeout=", + strprintf(_("Specify connection timeout in milliseconds " + "(minimum: 1, default: %d)"), + DEFAULT_CONNECT_TIMEOUT), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-torcontrol=:", + strprintf(_("Tor control port to use if onion listening " + "enabled (default: %s)"), + DEFAULT_TOR_CONTROL), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-torpassword=", + _("Tor control port password (default: empty)"), false, + OptionsCategory::CONNECTION); #ifdef USE_UPNP #if USE_UPNP - strUsage += - HelpMessageOpt("-upnp", _("Use UPnP to map the listening port " - "(default: 1 when listening and no -proxy)")); + gArgs.AddArg("-upnp", + _("Use UPnP to map the listening port (default: 1 when " + "listening and no -proxy)"), + false, OptionsCategory::CONNECTION); #else - strUsage += HelpMessageOpt( + gArgs.AddArg( "-upnp", - strprintf(_("Use UPnP to map the listening port (default: %u)"), 0)); + strprintf(_("Use UPnP to map the listening port (default: %u)"), 0), + false, OptionsCategory::CONNECTION); #endif #endif - strUsage += - HelpMessageOpt("-whitebind=", - _("Bind to given address and whitelist peers connecting " - "to it. Use [host]:port notation for IPv6")); - strUsage += HelpMessageOpt( - "-whitelist=", - _("Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) " - "or CIDR notated network (e.g. 1.2.3.0/24). Can be specified " - "multiple times.") + - " " + - _("Whitelisted peers cannot be DoS banned and their transactions " - "are always relayed, even if they are already in the mempool, " - "useful e.g. for a gateway")); - strUsage += HelpMessageOpt( + gArgs.AddArg("-whitebind=", + _("Bind to given address and whitelist peers connecting to " + "it. Use [host]:port notation for IPv6"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg("-whitelist=", + _("Whitelist peers connecting from the given IP address (e.g. " + "1.2.3.4) or CIDR notated network (e.g. 1.2.3.0/24). Can be " + "specified multiple times.") + + " " + + _("Whitelisted peers cannot be DoS banned and their " + "transactions are always relayed, even if they are " + "already in the mempool, useful e.g. for a gateway"), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-whitelistrelay", strprintf(_("Accept relayed transactions received from whitelisted " "peers even when not relaying transactions (default: %d)"), - DEFAULT_WHITELISTRELAY)); - strUsage += HelpMessageOpt( + DEFAULT_WHITELISTRELAY), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-whitelistforcerelay", strprintf(_("Force relay of transactions from whitelisted peers even " "if they violate local relay policy (default: %d)"), - DEFAULT_WHITELISTFORCERELAY)); - strUsage += HelpMessageOpt( + DEFAULT_WHITELISTFORCERELAY), + false, OptionsCategory::CONNECTION); + gArgs.AddArg( "-maxuploadtarget=", strprintf(_("Tries to keep outbound traffic under the given target (in " "MiB per 24h), 0 = no limit (default: %d)"), - DEFAULT_MAX_UPLOAD_TARGET)); + DEFAULT_MAX_UPLOAD_TARGET), + false, OptionsCategory::CONNECTION); - strUsage += g_wallet_init_interface.GetHelpString(showDebug); + g_wallet_init_interface.AddWalletOptions(); #if ENABLE_ZMQ - strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); - strUsage += HelpMessageOpt("-zmqpubhashblock=
", - _("Enable publish hash block in
")); - strUsage += - HelpMessageOpt("-zmqpubhashtx=
", - _("Enable publish hash transaction in
")); - strUsage += HelpMessageOpt("-zmqpubrawblock=
", - _("Enable publish raw block in
")); - strUsage += - HelpMessageOpt("-zmqpubrawtx=
", - _("Enable publish raw transaction in
")); + gArgs.AddArg("-zmqpubhashblock=
", + _("Enable publish hash block in
"), false, + OptionsCategory::ZMQ); + gArgs.AddArg("-zmqpubhashtx=
", + _("Enable publish hash transaction in
"), false, + OptionsCategory::ZMQ); + gArgs.AddArg("-zmqpubrawblock=
", + _("Enable publish raw block in
"), false, + OptionsCategory::ZMQ); + gArgs.AddArg("-zmqpubrawtx=
", + _("Enable publish raw transaction in
"), false, + OptionsCategory::ZMQ); #endif - strUsage += HelpMessageGroup(_("Debugging/Testing options:")); - strUsage += HelpMessageOpt("-uacomment=", - _("Append comment to the user agent string")); - if (showDebug) { - strUsage += HelpMessageOpt( - "-checkblocks=", - strprintf( - _("How many blocks to check at startup (default: %u, 0 = all)"), - DEFAULT_CHECKBLOCKS)); - strUsage += - HelpMessageOpt("-checklevel=", - strprintf(_("How thorough the block verification of " - "-checkblocks is (0-4, default: %u)"), - DEFAULT_CHECKLEVEL)); - strUsage += HelpMessageOpt( - "-checkblockindex", - strprintf("Do a full consistency check for mapBlockIndex, " - "setBlockIndexCandidates, chainActive and " - "mapBlocksUnlinked occasionally. Also sets -checkmempool " - "(default: %u)", - defaultChainParams->DefaultConsistencyChecks())); - strUsage += HelpMessageOpt( - "-checkmempool=", - strprintf("Run checks every transactions (default: %u)", - defaultChainParams->DefaultConsistencyChecks())); - strUsage += HelpMessageOpt( - "-checkpoints", strprintf("Only accept block chain matching " - "built-in checkpoints (default: %d)", - DEFAULT_CHECKPOINTS_ENABLED)); - strUsage += - HelpMessageOpt("-deprecatedrpc=", - "Allows deprecated RPC method(s) to be used"); - strUsage += - HelpMessageOpt("-dropmessagestest=", - "Randomly drop 1 of every network messages"); - strUsage += HelpMessageOpt( - "-stopafterblockimport", - strprintf( - "Stop running after importing blocks from disk (default: %d)", - DEFAULT_STOPAFTERBLOCKIMPORT)); - strUsage += HelpMessageOpt( - "-stopatheight", strprintf("Stop running after reaching the given " - "height in the main chain (default: %u)", - DEFAULT_STOPATHEIGHT)); - strUsage += HelpMessageOpt( - "-limitancestorcount=", - strprintf("Do not accept transactions if number of in-mempool " - "ancestors is or more (default: %u)", - DEFAULT_ANCESTOR_LIMIT)); - strUsage += - HelpMessageOpt("-limitancestorsize=", - strprintf("Do not accept transactions whose size " - "with all in-mempool ancestors exceeds " - " kilobytes (default: %u)", - DEFAULT_ANCESTOR_SIZE_LIMIT)); - strUsage += HelpMessageOpt( - "-limitdescendantcount=", - strprintf("Do not accept transactions if any ancestor would have " - " or more in-mempool descendants (default: %u)", - DEFAULT_DESCENDANT_LIMIT)); - strUsage += HelpMessageOpt( - "-limitdescendantsize=", - strprintf("Do not accept transactions if any ancestor would have " - "more than kilobytes of in-mempool descendants " - "(default: %u).", - DEFAULT_DESCENDANT_SIZE_LIMIT)); - strUsage += HelpMessageOpt("-addrmantest", - "Allows to test address relay on localhost"); - } - strUsage += HelpMessageOpt( - "-debug=", - strprintf(_("Output debugging information (default: %u, supplying " - " is optional)"), - 0) + - ". " + - _("If is not supplied or if = 1, output all " - "debugging information.") + - _(" can be:") + " " + ListLogCategories() + "."); - strUsage += HelpMessageOpt( + gArgs.AddArg( + "-checkblocks=", + strprintf( + _("How many blocks to check at startup (default: %u, 0 = all)"), + DEFAULT_CHECKBLOCKS), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-checklevel=", + strprintf(_("How thorough the block verification of " + "-checkblocks is (0-4, default: %u)"), + DEFAULT_CHECKLEVEL), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-checkblockindex", + strprintf("Do a full consistency check for mapBlockIndex, " + "setBlockIndexCandidates, chainActive and mapBlocksUnlinked " + "occasionally. Also sets -checkmempool (default: %u)", + defaultChainParams->DefaultConsistencyChecks()), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-checkmempool=", + strprintf("Run checks every transactions (default: %u)", + defaultChainParams->DefaultConsistencyChecks()), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-checkpoints", + strprintf("Only accept block chain matching built-in " + "checkpoints (default: %d)", + DEFAULT_CHECKPOINTS_ENABLED), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-deprecatedrpc=", + "Allows deprecated RPC method(s) to be used", true, + OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-dropmessagestest=", + "Randomly drop 1 of every network messages", true, + OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-stopafterblockimport", + strprintf("Stop running after importing blocks from disk (default: %d)", + DEFAULT_STOPAFTERBLOCKIMPORT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-stopatheight", + strprintf("Stop running after reaching the given height in " + "the main chain (default: %u)", + DEFAULT_STOPATHEIGHT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-limitancestorcount=", + strprintf("Do not accept transactions if number of in-mempool " + "ancestors is or more (default: %u)", + DEFAULT_ANCESTOR_LIMIT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-limitancestorsize=", + strprintf("Do not accept transactions whose size with all in-mempool " + "ancestors exceeds kilobytes (default: %u)", + DEFAULT_ANCESTOR_SIZE_LIMIT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-limitdescendantcount=", + strprintf("Do not accept transactions if any ancestor would have " + "or more in-mempool descendants (default: %u)", + DEFAULT_DESCENDANT_LIMIT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-limitdescendantsize=", + strprintf("Do not accept transactions if any ancestor would have more " + "than kilobytes of in-mempool descendants (default: %u).", + DEFAULT_DESCENDANT_SIZE_LIMIT), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-addrmantest", "Allows to test address relay on localhost", + true, OptionsCategory::DEBUG_TEST); + + gArgs.AddArg("-debug=", + strprintf(_("Output debugging information (default: %u, " + "supplying is optional)"), + 0) + + ". " + + _("If is not supplied or if = 1, " + "output all debugging information.") + + _(" can be:") + " " + ListLogCategories() + ".", + false, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( "-debugexclude=", strprintf(_("Exclude debugging information for a category. Can be used " "in conjunction with -debug=1 to output debug logs for all " - "categories except one or more specified categories."))); - strUsage += HelpMessageOpt( - "-help-debug", - _("Show all debugging options (usage: --help -help-debug)")); - strUsage += HelpMessageOpt( + "categories except one or more specified categories.")), + false, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-help-debug", + _("Show all debugging options (usage: --help -help-debug)"), + false, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( "-logips", strprintf(_("Include IP addresses in debug output (default: %d)"), - DEFAULT_LOGIPS)); - strUsage += HelpMessageOpt( + DEFAULT_LOGIPS), + false, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( "-logtimestamps", strprintf(_("Prepend debug output with timestamp (default: %d)"), - DEFAULT_LOGTIMESTAMPS)); - if (showDebug) { - strUsage += HelpMessageOpt( - "-logtimemicros", - strprintf( - "Add microsecond precision to debug timestamps (default: %d)", - DEFAULT_LOGTIMEMICROS)); - strUsage += HelpMessageOpt( - "-mocktime=", - "Replace actual time with seconds since epoch (default: 0)"); - strUsage += HelpMessageOpt( - "-limitfreerelay=", - strprintf("Continuously rate-limit free transactions to *1000 " - "bytes per minute (default: %u)", - DEFAULT_LIMITFREERELAY)); - strUsage += - HelpMessageOpt("-relaypriority", - strprintf("Require high priority for relaying free " - "or low-fee transactions (default: %d)", - DEFAULT_RELAYPRIORITY)); - strUsage += HelpMessageOpt( - "-maxsigcachesize=", - strprintf("Limit size of signature cache to MiB (default: %u)", - DEFAULT_MAX_SIG_CACHE_SIZE)); - strUsage += HelpMessageOpt( - "-maxscriptcachesize=", - strprintf("Limit size of script cache to MiB (default: %u)", - DEFAULT_MAX_SCRIPT_CACHE_SIZE)); - strUsage += HelpMessageOpt( - "-maxtipage=", - strprintf("Maximum tip age in seconds to consider node in initial " - "block download (default: %u)", - DEFAULT_MAX_TIP_AGE)); - } - strUsage += HelpMessageOpt( - "-excessutxocharge=", - strprintf(_("Fees (in %s/kB) to charge per utxo created for" - "relaying, and mining (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_UTXO_FEE))); - strUsage += HelpMessageOpt( - "-minrelaytxfee=", - strprintf( - _("Fees (in %s/kB) smaller than this are considered zero fee for " - "relaying, mining and transaction creation (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE_PER_KB))); - strUsage += HelpMessageOpt( + DEFAULT_LOGTIMESTAMPS), + false, OptionsCategory::DEBUG_TEST); + + gArgs.AddArg( + "-logtimemicros", + strprintf("Add microsecond precision to debug timestamps (default: %d)", + DEFAULT_LOGTIMEMICROS), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-mocktime=", + "Replace actual time with seconds since epoch (default: 0)", true, + OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-maxsigcachesize=", + strprintf("Limit size of signature cache to MiB (default: %u)", + DEFAULT_MAX_SIG_CACHE_SIZE), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( + "-maxscriptcachesize=", + strprintf("Limit size of script cache to MiB (default: %u)", + DEFAULT_MAX_SCRIPT_CACHE_SIZE), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-maxtipage=", + strprintf("Maximum tip age in seconds to consider node in " + "initial block download (default: %u)", + DEFAULT_MAX_TIP_AGE), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg( "-maxtxfee=", strprintf(_("Maximum total fees (in %s) to use in a single wallet " "transaction or raw transaction; setting this too low may " "abort large transactions (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE))); - strUsage += HelpMessageOpt( + CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE)), + false, OptionsCategory::DEBUG_TEST); + + gArgs.AddArg( "-printtoconsole", - _("Send trace/debug info to console instead of debug.log file")); - if (showDebug) { - strUsage += HelpMessageOpt( - "-printpriority", strprintf("Log transaction priority and fee per " - "kB when mining blocks (default: %d)", - DEFAULT_PRINTPRIORITY)); - } - strUsage += HelpMessageOpt("-shrinkdebugfile", - _("Shrink debug.log file on client startup " - "(default: 1 when no -debug)")); - - AppendParamsHelpMessages(strUsage, showDebug); - - strUsage += HelpMessageGroup(_("Node relay options:")); - if (showDebug) { - strUsage += HelpMessageOpt( - "-acceptnonstdtxn", - strprintf( - "Relay and mine \"non-standard\" transactions (%sdefault: %u)", - "testnet/regtest only; ", - defaultChainParams->RequireStandard())); - strUsage += - HelpMessageOpt("-excessiveblocksize=", - strprintf(_("Do not accept blocks larger than this " - "limit, in bytes (default: %d)"), - DEFAULT_MAX_BLOCK_SIZE)); - strUsage += HelpMessageOpt( - "-dustrelayfee=", - strprintf("Fee rate (in %s/kB) used to defined dust, the value of " - "an output such that it will cost about 1/3 of its value " - "in fees at this fee rate to spend it. (default: %s)", - CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE))); - } - strUsage += - HelpMessageOpt("-bytespersigop", - strprintf(_("Equivalent bytes per sigop in transactions " - "for relay and mining (default: %u)"), - DEFAULT_BYTES_PER_SIGOP)); - strUsage += HelpMessageOpt( + _("Send trace/debug info to console instead of debug.log file"), false, + OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-printpriority", + strprintf("Log transaction priority and fee per kB when " + "mining blocks (default: %d)", + DEFAULT_PRINTPRIORITY), + true, OptionsCategory::DEBUG_TEST); + gArgs.AddArg("-shrinkdebugfile", + _("Shrink debug.log file on client startup (default: 1 when " + "no -debug)"), + false, OptionsCategory::DEBUG_TEST); + + gArgs.AddArg("-uacomment=", + _("Append comment to the user agent string"), false, + OptionsCategory::DEBUG_TEST); + + SetupChainParamsBaseOptions(); + + gArgs.AddArg( + "-acceptnonstdtxn", + strprintf( + "Relay and mine \"non-standard\" transactions (%sdefault: %u)", + "testnet/regtest only; ", defaultChainParams->RequireStandard()), + true, OptionsCategory::NODE_RELAY); + gArgs.AddArg("-excessiveblocksize=", + strprintf(_("Do not accept blocks larger than this limit, in " + "bytes (default: %d)"), + DEFAULT_MAX_BLOCK_SIZE), + true, OptionsCategory::NODE_RELAY); + gArgs.AddArg( + "-dustrelayfee=", + strprintf("Fee rate (in %s/kB) used to defined dust, the value of an " + "output such that it will cost about 1/3 of its value in " + "fees at this fee rate to spend it. (default: %s)", + CURRENCY_UNIT, FormatMoney(DUST_RELAY_TX_FEE)), + true, OptionsCategory::NODE_RELAY); + gArgs.AddArg("-limitfreerelay=", + strprintf("Continuously rate-limit free transactions to " + "*1000 bytes per minute (default: %u)", + DEFAULT_LIMITFREERELAY), + true, OptionsCategory::NODE_RELAY); + gArgs.AddArg("-relaypriority", + strprintf("Require high priority for relaying free or low-fee " + "transactions (default: %d)", + DEFAULT_RELAYPRIORITY), + true, OptionsCategory::NODE_RELAY); + + gArgs.AddArg("-bytespersigop", + strprintf(_("Equivalent bytes per sigop in transactions for " + "relay and mining (default: %u)"), + DEFAULT_BYTES_PER_SIGOP), + false, OptionsCategory::NODE_RELAY); + gArgs.AddArg( "-datacarrier", strprintf(_("Relay and mine data carrier transactions (default: %d)"), - DEFAULT_ACCEPT_DATACARRIER)); - strUsage += HelpMessageOpt( - "-datacarriersize", - strprintf(_("Maximum size of data in data carrier transactions we " - "relay and mine (default: %u)"), - MAX_OP_RETURN_RELAY)); - - strUsage += HelpMessageGroup(_("Block creation options:")); - strUsage += HelpMessageOpt( - "-blockmaxsize=", - strprintf(_("Set maximum block size in bytes (default: %d)"), - DEFAULT_MAX_GENERATED_BLOCK_SIZE)); - strUsage += HelpMessageOpt( + DEFAULT_ACCEPT_DATACARRIER), + false, OptionsCategory::NODE_RELAY); + gArgs.AddArg("-datacarriersize", + strprintf(_("Maximum size of data in data carrier " + "transactions we relay and mine (default: %u)"), + MAX_OP_RETURN_RELAY), + false, OptionsCategory::NODE_RELAY); + gArgs.AddArg( + "-minrelaytxfee=", + strprintf( + _("Fees (in %s/kB) smaller than this are considered zero fee for " + "relaying, mining and transaction creation (default: %s)"), + CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE_PER_KB)), + false, OptionsCategory::NODE_RELAY); + + // Not sure this really belongs here, but it will do for now. + // FIXME: This doesn't work anyways. + gArgs.AddArg("-excessutxocharge=", + strprintf(_("Fees (in %s/kB) to charge per utxo created for " + "relaying, and mining (default: %s)"), + CURRENCY_UNIT, FormatMoney(DEFAULT_UTXO_FEE)), + true, OptionsCategory::NODE_RELAY); + + gArgs.AddArg("-blockmaxsize=", + strprintf(_("Set maximum block size in bytes (default: %d)"), + DEFAULT_MAX_GENERATED_BLOCK_SIZE), + false, OptionsCategory::BLOCK_CREATION); + gArgs.AddArg( "-blockprioritypercentage=", strprintf(_("Set maximum percentage of a block reserved to " "high-priority/low-fee transactions (default: %d)"), - DEFAULT_BLOCK_PRIORITY_PERCENTAGE)); - strUsage += HelpMessageOpt( + DEFAULT_BLOCK_PRIORITY_PERCENTAGE), + false, OptionsCategory::BLOCK_CREATION); + gArgs.AddArg( "-blockmintxfee=", strprintf(_("Set lowest fee rate (in %s/kB) for transactions to be " "included in block creation. (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB))); - if (showDebug) { - strUsage += - HelpMessageOpt("-blockversion=", - "Override block version to test forking scenarios"); - } - - strUsage += HelpMessageGroup(_("RPC server options:")); - strUsage += HelpMessageOpt("-server", - _("Accept command line and JSON-RPC commands")); - strUsage += HelpMessageOpt( - "-rest", strprintf(_("Accept public REST requests (default: %d)"), - DEFAULT_REST_ENABLE)); - strUsage += HelpMessageOpt( + CURRENCY_UNIT, FormatMoney(DEFAULT_BLOCK_MIN_TX_FEE_PER_KB)), + false, OptionsCategory::BLOCK_CREATION); + + gArgs.AddArg("-blockversion=", + "Override block version to test forking scenarios", true, + OptionsCategory::BLOCK_CREATION); + + gArgs.AddArg("-server", _("Accept command line and JSON-RPC commands"), + false, OptionsCategory::RPC); + gArgs.AddArg("-rest", + strprintf(_("Accept public REST requests (default: %d)"), + DEFAULT_REST_ENABLE), + false, OptionsCategory::RPC); + gArgs.AddArg( "-rpcbind=", _("Bind to given address to listen for JSON-RPC connections. Use " "[host]:port notation for IPv6. This option can be specified " - "multiple times (default: bind to all interfaces)")); - strUsage += - HelpMessageOpt("-rpccookiefile=", - _("Location of the auth cookie (default: data dir)")); - strUsage += HelpMessageOpt("-rpcuser=", - _("Username for JSON-RPC connections")); - strUsage += HelpMessageOpt("-rpcpassword=", - _("Password for JSON-RPC connections")); - strUsage += HelpMessageOpt( + "multiple times (default: bind to all interfaces)"), + false, OptionsCategory::RPC); + gArgs.AddArg("-rpccookiefile=", + _("Location of the auth cookie (default: data dir)"), false, + OptionsCategory::RPC); + gArgs.AddArg("-rpcuser=", _("Username for JSON-RPC connections"), + false, OptionsCategory::RPC); + gArgs.AddArg("-rpcpassword=", _("Password for JSON-RPC connections"), + false, OptionsCategory::RPC); + gArgs.AddArg( "-rpcauth=", _("Username and hashed password for JSON-RPC connections. The field " " comes in the format: :$. A canonical " "python script is included in share/rpcuser. The client then " "connects normally using the " "rpcuser=/rpcpassword= pair of arguments. This " - "option can be specified multiple times")); - strUsage += HelpMessageOpt( + "option can be specified multiple times"), + false, OptionsCategory::RPC); + gArgs.AddArg( "-rpcport=", strprintf(_("Listen for JSON-RPC connections on (default: %u or " "testnet: %u)"), - defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort())); - strUsage += HelpMessageOpt( - "-rpcallowip=", - _("Allow JSON-RPC connections from specified source. Valid for " - "are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. " - "1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This " - "option can be specified multiple times")); - strUsage += HelpMessageOpt( + defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()), + false, OptionsCategory::RPC); + gArgs.AddArg("-rpcallowip=", + _("Allow JSON-RPC connections from specified source. Valid " + "for are a single IP (e.g. 1.2.3.4), a network/netmask " + "(e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. " + "1.2.3.4/24). This option can be specified multiple times"), + false, OptionsCategory::RPC); + gArgs.AddArg( "-rpcthreads=", strprintf( _("Set the number of threads to service RPC calls (default: %d)"), - DEFAULT_HTTP_THREADS)); - strUsage += HelpMessageOpt( + DEFAULT_HTTP_THREADS), + false, OptionsCategory::RPC); + gArgs.AddArg( "-rpccorsdomain=value", - "Domain from which to accept cross origin requests (browser enforced)"); - if (showDebug) { - strUsage += HelpMessageOpt( - "-rpcworkqueue=", strprintf("Set the depth of the work queue to " - "service RPC calls (default: %d)", - DEFAULT_HTTP_WORKQUEUE)); - strUsage += HelpMessageOpt( - "-rpcservertimeout=", - strprintf("Timeout during HTTP requests (default: %d)", - DEFAULT_HTTP_SERVER_TIMEOUT)); - } - - return strUsage; + "Domain from which to accept cross origin requests (browser enforced)", + false, OptionsCategory::RPC); + + gArgs.AddArg("-rpcworkqueue=", + strprintf("Set the depth of the work queue to service RPC " + "calls (default: %d)", + DEFAULT_HTTP_WORKQUEUE), + true, OptionsCategory::RPC); + gArgs.AddArg("-rpcservertimeout=", + strprintf("Timeout during HTTP requests (default: %d)", + DEFAULT_HTTP_SERVER_TIMEOUT), + true, OptionsCategory::RPC); } std::string LicenseInfo() { diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -7,7 +7,6 @@ #include // For banmap_t #include // For Amount -#include // For HelpMessageMode #include // For CConnman::NumConnections #include // For Network @@ -86,8 +85,8 @@ //! Return whether shutdown was requested. virtual bool shutdownRequested() = 0; - //! Get help message string. - virtual std::string helpMessage(HelpMessageMode mode) = 0; + //! Setup arguments + virtual void setupServerArgs() = 0; //! Map port. virtual void mapPort(bool use_upnp) = 0; diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -96,9 +96,7 @@ StopMapPort(); } } - std::string helpMessage(HelpMessageMode mode) override { - return HelpMessage(mode); - } + void setupServerArgs() override { return SetupServerArgs(); } bool getProxy(Network net, proxyType &proxy_info) override { return GetProxy(net, proxy_info); } diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -538,6 +538,50 @@ return window->winId(); } +static void SetupUIArgs() { +#ifdef ENABLE_WALLET + gArgs.AddArg("-allowselfsignedrootcertificates", + strprintf("Allow self signed root certificates (default: %d)", + DEFAULT_SELFSIGNED_ROOTCERTS), + true, OptionsCategory::GUI); +#endif + gArgs.AddArg( + "-choosedatadir", + strprintf(QObject::tr("Choose data directory on startup (default: %d)") + .toStdString(), + DEFAULT_CHOOSE_DATADIR), + false, OptionsCategory::GUI); + gArgs.AddArg( + "-lang=", + QObject::tr( + "Set language, for example \"de_DE\" (default: system locale)") + .toStdString(), + false, OptionsCategory::GUI); + gArgs.AddArg("-min", QObject::tr("Start minimized").toStdString(), false, + OptionsCategory::GUI); + gArgs.AddArg( + "-rootcertificates=", + QObject::tr( + "Set SSL root certificates for payment request (default: -system-)") + .toStdString(), + false, OptionsCategory::GUI); + gArgs.AddArg( + "-splash", + strprintf(QObject::tr("Show splash screen on startup (default: %d)") + .toStdString(), + DEFAULT_SPLASHSCREEN), + false, OptionsCategory::GUI); + gArgs.AddArg( + "-resetguisettings", + QObject::tr("Reset all settings changed in the GUI").toStdString(), + false, OptionsCategory::GUI); + gArgs.AddArg("-uiplatform", + strprintf("Select platform to customize UI for (one of " + "windows, macosx, other; default: %s)", + BitcoinGUI::DEFAULT_UIPLATFORM), + true, OptionsCategory::GUI); +} + #ifndef BITCOIN_QT_TEST static void MigrateSettings() { @@ -584,6 +628,8 @@ /// 1. Parse command-line options. These take precedence over anything else. // Command-line options take precedence: + node->setupServerArgs(); + SetupUIArgs(); node->parseParameters(argc, argv); // Do not refer to data directory yet, this can be overridden by diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -77,44 +77,7 @@ cursor.insertText(header); cursor.insertBlock(); - std::string strUsage = node.helpMessage(HelpMessageMode::BITCOIN_QT); - const bool showDebug = gArgs.GetBoolArg("-help-debug", false); - strUsage += HelpMessageGroup(tr("UI Options:").toStdString()); - if (showDebug) { - strUsage += HelpMessageOpt( - "-allowselfsignedrootcertificates", - strprintf("Allow self signed root certificates (default: %d)", - DEFAULT_SELFSIGNED_ROOTCERTS)); - } - strUsage += HelpMessageOpt( - "-choosedatadir", - strprintf(tr("Choose data directory on startup (default: %d)") - .toStdString(), - DEFAULT_CHOOSE_DATADIR)); - strUsage += HelpMessageOpt( - "-lang=", - tr("Set language, for example \"de_DE\" (default: system locale)") - .toStdString()); - strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString()); - strUsage += HelpMessageOpt("-rootcertificates=", - tr("Set SSL root certificates for payment " - "request (default: -system-)") - .toStdString()); - strUsage += HelpMessageOpt( - "-splash", - strprintf( - tr("Show splash screen on startup (default: %d)").toStdString(), - DEFAULT_SPLASHSCREEN)); - strUsage += HelpMessageOpt( - "-resetguisettings", - tr("Reset all settings changed in the GUI").toStdString()); - if (showDebug) { - strUsage += HelpMessageOpt( - "-uiplatform", - strprintf("Select platform to customize UI for (one of " - "windows, macosx, other; default: %s)", - BitcoinGUI::DEFAULT_UIPLATFORM)); - } + std::string strUsage = gArgs.GetHelpMessage(); QString coreOptions = QString::fromStdString(strUsage); text = version + "\n\n" + header + "\n" + coreOptions; diff --git a/src/util.h b/src/util.h --- a/src/util.h +++ b/src/util.h @@ -105,6 +105,22 @@ #endif } +enum class OptionsCategory { + OPTIONS, + CONNECTION, + WALLET, + WALLET_DEBUG_TEST, + ZMQ, + DEBUG_TEST, + CHAINPARAMS, + NODE_RELAY, + BLOCK_CREATION, + RPC, + GUI, + COMMANDS, + REGISTER_COMMANDS +}; + class ArgsManager { protected: friend class ArgsManagerHelper; @@ -114,6 +130,9 @@ std::map> m_config_args; std::string m_network; std::set m_network_only_args; + std::map, + std::pair> + m_available_args; void ReadConfigStream(std::istream &stream); @@ -221,8 +240,19 @@ */ std::string GetChainName() const; + /** + * Add argument + */ + void AddArg(const std::string &name, const std::string &help, + const bool debug_only, const OptionsCategory &cat); + // Remove an arg setting, used only in testing void ClearArg(const std::string &strArg); + + /** + * Get the help string + */ + std::string GetHelpMessage(); }; extern ArgsManager gArgs; diff --git a/src/util.cpp b/src/util.cpp --- a/src/util.cpp +++ b/src/util.cpp @@ -599,12 +599,64 @@ m_override_args[strArg].push_back(strValue); } +void ArgsManager::AddArg(const std::string &name, const std::string &help, + const bool debug_only, const OptionsCategory &cat) { + std::pair key(cat, name); + assert(m_available_args.count(key) == 0); + m_available_args.emplace(key, + std::pair(help, debug_only)); +} + void ArgsManager::ClearArg(const std::string &strArg) { LOCK(cs_args); m_override_args.erase(strArg); m_config_args.erase(strArg); } +std::string ArgsManager::GetHelpMessage() { + const bool show_debug = gArgs.GetBoolArg("-help-debug", false); + + std::string usage = HelpMessageGroup(_("Options:")); + + OptionsCategory last_cat = OptionsCategory::OPTIONS; + for (auto &arg : m_available_args) { + if (arg.first.first != last_cat) { + last_cat = arg.first.first; + if (last_cat == OptionsCategory::CONNECTION) { + usage += HelpMessageGroup(_("Connection options:")); + } else if (last_cat == OptionsCategory::ZMQ) { + usage += HelpMessageGroup(_("ZeroMQ notification options:")); + } else if (last_cat == OptionsCategory::DEBUG_TEST) { + usage += HelpMessageGroup(_("Debugging/Testing options:")); + } else if (last_cat == OptionsCategory::NODE_RELAY) { + usage += HelpMessageGroup(_("Node relay options:")); + } else if (last_cat == OptionsCategory::BLOCK_CREATION) { + usage += HelpMessageGroup(_("Block creation options:")); + } else if (last_cat == OptionsCategory::RPC) { + usage += HelpMessageGroup(_("RPC server options:")); + } else if (last_cat == OptionsCategory::WALLET) { + usage += HelpMessageGroup(_("Wallet options:")); + } else if (last_cat == OptionsCategory::WALLET_DEBUG_TEST && + show_debug) { + usage += + HelpMessageGroup(_("Wallet debugging/testing options:")); + } else if (last_cat == OptionsCategory::CHAINPARAMS) { + usage += HelpMessageGroup(_("Chain selection options:")); + } else if (last_cat == OptionsCategory::GUI) { + usage += HelpMessageGroup(_("UI Options:")); + } else if (last_cat == OptionsCategory::COMMANDS) { + usage += HelpMessageGroup(_("Commands:")); + } else if (last_cat == OptionsCategory::REGISTER_COMMANDS) { + usage += HelpMessageGroup(_("Register Commands:")); + } + } + if (show_debug || !arg.second.second) { + usage += HelpMessageOpt(arg.first.second, arg.second.first); + } + } + return usage; +} + bool HelpRequested(const ArgsManager &args) { return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help"); } diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -19,7 +19,7 @@ class WalletInit : public WalletInitInterface { public: //! Return the wallets help message. - std::string GetHelpString(bool showDebug) const override; + void AddWalletOptions() const override; //! Wallets parameter interaction bool ParameterInteraction() const override; @@ -52,90 +52,92 @@ const WalletInitInterface &g_wallet_init_interface = WalletInit(); -std::string WalletInit::GetHelpString(bool showDebug) const { - std::string strUsage = HelpMessageGroup(_("Wallet options:")); - strUsage += HelpMessageOpt( - "-disablewallet", - _("Do not load the wallet and disable wallet RPC calls")); - strUsage += HelpMessageOpt( - "-keypool=", strprintf(_("Set key pool size to (default: %u)"), - DEFAULT_KEYPOOL_SIZE)); - strUsage += HelpMessageOpt( - "-fallbackfee=", - strprintf(_("A fee rate (in %s/kB) that will be used when fee " - "estimation has insufficient data (default: %s)"), - CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE))); - strUsage += HelpMessageOpt( +void WalletInit::AddWalletOptions() const { + gArgs.AddArg("-disablewallet", + _("Do not load the wallet and disable wallet RPC calls"), + false, OptionsCategory::WALLET); + gArgs.AddArg("-keypool=", + strprintf(_("Set key pool size to (default: %u)"), + DEFAULT_KEYPOOL_SIZE), + false, OptionsCategory::WALLET); + gArgs.AddArg("-fallbackfee=", + strprintf(_("A fee rate (in %s/kB) that will be used when fee " + "estimation has insufficient data (default: %s)"), + CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE)), + false, OptionsCategory::WALLET); + gArgs.AddArg( "-paytxfee=", strprintf( _("Fee (in %s/kB) to add to transactions you send (default: %s)"), - CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK()))); - strUsage += HelpMessageOpt( + CURRENCY_UNIT, FormatMoney(payTxFee.GetFeePerK())), + false, OptionsCategory::WALLET); + gArgs.AddArg( "-rescan", - _("Rescan the block chain for missing wallet transactions on startup")); - strUsage += HelpMessageOpt( + _("Rescan the block chain for missing wallet transactions on startup"), + false, OptionsCategory::WALLET); + gArgs.AddArg( "-salvagewallet", - _("Attempt to recover private keys from a corrupt wallet on startup")); - - strUsage += - HelpMessageOpt("-spendzeroconfchange", - strprintf(_("Spend unconfirmed change when sending " - "transactions (default: %d)"), - DEFAULT_SPEND_ZEROCONF_CHANGE)); - strUsage += HelpMessageOpt( + _("Attempt to recover private keys from a corrupt wallet on startup"), + false, OptionsCategory::WALLET); + + gArgs.AddArg("-spendzeroconfchange", + strprintf(_("Spend unconfirmed change when sending " + "transactions (default: %d)"), + DEFAULT_SPEND_ZEROCONF_CHANGE), + false, OptionsCategory::WALLET); + gArgs.AddArg( "-usehd", _("Use hierarchical deterministic key generation (HD) after BIP32. " "Only has effect during wallet creation/first start") + - " " + strprintf(_("(default: %d)"), DEFAULT_USE_HD_WALLET)); - strUsage += HelpMessageOpt("-upgradewallet", - _("Upgrade wallet to latest format on startup")); - strUsage += - HelpMessageOpt("-wallet=", - _("Specify wallet file (within data directory)") + " " + - strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT)); - strUsage += HelpMessageOpt( - "-walletbroadcast", - _("Make the wallet broadcast transactions") + " " + - strprintf(_("(default: %d)"), DEFAULT_WALLETBROADCAST)); - strUsage += HelpMessageOpt( - "-walletdir=", - _("Specify directory to hold wallets (default: /wallets if it " - "exists, otherwise )")); - strUsage += HelpMessageOpt("-walletnotify=", - _("Execute command when a wallet transaction " - "changes (%s in cmd is replaced by TxID)")); - strUsage += HelpMessageOpt( - "-zapwallettxes=", - _("Delete all wallet transactions and only recover those parts of the " - "blockchain through -rescan on startup") + - " " + - _("(1 = keep tx meta data e.g. account owner and payment " - "request information, 2 = drop tx meta data)")); - - if (showDebug) { - strUsage += HelpMessageGroup(_("Wallet debugging/testing options:")); - - strUsage += HelpMessageOpt( - "-dblogsize=", - strprintf("Flush wallet database activity from memory to disk log " - "every megabytes (default: %u)", - DEFAULT_WALLET_DBLOGSIZE)); - strUsage += HelpMessageOpt( - "-flushwallet", - strprintf("Run a thread to flush wallet periodically (default: %d)", - DEFAULT_FLUSHWALLET)); - strUsage += HelpMessageOpt( - "-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db " - "environment (default: %d)", - DEFAULT_WALLET_PRIVDB)); - strUsage += HelpMessageOpt( - "-walletrejectlongchains", - strprintf(_("Wallet will not create transactions that violate " - "mempool chain limits (default: %d)"), - DEFAULT_WALLET_REJECT_LONG_CHAINS)); - } - - return strUsage; + " " + strprintf(_("(default: %d)"), DEFAULT_USE_HD_WALLET), + false, OptionsCategory::WALLET); + gArgs.AddArg("-upgradewallet", + _("Upgrade wallet to latest format on startup"), false, + OptionsCategory::WALLET); + gArgs.AddArg("-wallet=", + _("Specify wallet file (within data directory)") + " " + + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT), + false, OptionsCategory::WALLET); + gArgs.AddArg("-walletbroadcast", + _("Make the wallet broadcast transactions") + " " + + strprintf(_("(default: %d)"), DEFAULT_WALLETBROADCAST), + false, OptionsCategory::WALLET); + gArgs.AddArg("-walletdir=", + _("Specify directory to hold wallets (default: " + "/wallets if it exists, otherwise )"), + false, OptionsCategory::WALLET); + gArgs.AddArg("-walletnotify=", + _("Execute command when a wallet transaction changes (%s in " + "cmd is replaced by TxID)"), + false, OptionsCategory::WALLET); + gArgs.AddArg("-zapwallettxes=", + _("Delete all wallet transactions and only recover those " + "parts of the blockchain through -rescan on startup") + + " " + + _("(1 = keep tx meta data e.g. account owner and payment " + "request information, 2 = drop tx meta data)"), + false, OptionsCategory::WALLET); + + gArgs.AddArg("-dblogsize=", + strprintf("Flush wallet database activity from memory to disk " + "log every megabytes (default: %u)", + DEFAULT_WALLET_DBLOGSIZE), + true, OptionsCategory::WALLET_DEBUG_TEST); + gArgs.AddArg( + "-flushwallet", + strprintf("Run a thread to flush wallet periodically (default: %d)", + DEFAULT_FLUSHWALLET), + true, OptionsCategory::WALLET_DEBUG_TEST); + gArgs.AddArg("-privdb", + strprintf("Sets the DB_PRIVATE flag in the wallet db " + "environment (default: %d)", + DEFAULT_WALLET_PRIVDB), + true, OptionsCategory::WALLET_DEBUG_TEST); + gArgs.AddArg("-walletrejectlongchains", + strprintf(_("Wallet will not create transactions that violate " + "mempool chain limits (default: %d)"), + DEFAULT_WALLET_REJECT_LONG_CHAINS), + true, OptionsCategory::WALLET_DEBUG_TEST); } bool WalletInit::ParameterInteraction() const { diff --git a/src/walletinitinterface.h b/src/walletinitinterface.h --- a/src/walletinitinterface.h +++ b/src/walletinitinterface.h @@ -15,7 +15,7 @@ class WalletInitInterface { public: /** Get wallet help string */ - virtual std::string GetHelpString(bool showDebug) const = 0; + virtual void AddWalletOptions() const = 0; /** Check wallet parameter interaction */ virtual bool ParameterInteraction() const = 0; /** Register wallet RPC*/ diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -22,7 +22,7 @@ EXTENSIONS = ["*.c", "*.h", "*.cpp", "*.cc", "*.hpp"] REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\(\s*"(-[^"]+)"' -REGEX_DOC = 'HelpMessageOpt\(\s*"(-[^"=]+?)(?:=|")' +REGEX_DOC = 'AddArg\(\s*"(-[^"=]+?)(?:=|")' # list unsupported, deprecated and duplicate args as they need no documentation SET_DOC_OPTIONAL = set(['-benchmark',