Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show All 24 Lines | |||||
#include <cstdio> | #include <cstdio> | ||||
static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; | static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; | ||||
static const int DEFAULT_HTTP_CLIENT_TIMEOUT = 900; | static const int DEFAULT_HTTP_CLIENT_TIMEOUT = 900; | ||||
static const bool DEFAULT_NAMED = false; | static const bool DEFAULT_NAMED = false; | ||||
static const int CONTINUE_EXECUTION = -1; | static const int CONTINUE_EXECUTION = -1; | ||||
std::string HelpMessageCli() { | static void SetupCliArgs() { | ||||
const auto defaultBaseParams = | const auto defaultBaseParams = | ||||
CreateBaseChainParams(CBaseChainParams::MAIN); | CreateBaseChainParams(CBaseChainParams::MAIN); | ||||
const auto testnetBaseParams = | const auto testnetBaseParams = | ||||
CreateBaseChainParams(CBaseChainParams::TESTNET); | CreateBaseChainParams(CBaseChainParams::TESTNET); | ||||
std::string strUsage; | |||||
strUsage += HelpMessageGroup(_("Options:")); | gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS); | ||||
strUsage += HelpMessageOpt("-?", _("This help message")); | gArgs.AddArg("-conf=<file>", | ||||
strUsage += HelpMessageOpt( | strprintf(_("Specify configuration file (default: %s)"), | ||||
"-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), | BITCOIN_CONF_FILENAME), | ||||
BITCOIN_CONF_FILENAME)); | false, OptionsCategory::OPTIONS); | ||||
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory")); | gArgs.AddArg("-datadir=<dir>", _("Specify data directory"), false, | ||||
strUsage += HelpMessageOpt( | OptionsCategory::OPTIONS); | ||||
gArgs.AddArg( | |||||
"-getinfo", | "-getinfo", | ||||
_("Get general information from the remote server. Note that unlike " | _("Get general information from the remote server. Note that unlike " | ||||
"server-side RPC calls, the results of -getinfo is the result of " | "server-side RPC calls, the results of -getinfo is the result of " | ||||
"multiple non-atomic requests. Some entries in the result may " | "multiple non-atomic requests. Some entries in the result may " | ||||
"represent results from different states (e.g. wallet balance may be " | "represent results from different states (e.g. wallet balance may be " | ||||
"as of a different block from the chain state reported)")); | "as of a different block from the chain state reported)"), | ||||
AppendParamsHelpMessages(strUsage); | false, OptionsCategory::OPTIONS); | ||||
strUsage += HelpMessageOpt( | SetupChainParamsBaseOptions(); | ||||
gArgs.AddArg( | |||||
"-named", | "-named", | ||||
strprintf(_("Pass named instead of positional arguments (default: %s)"), | strprintf(_("Pass named instead of positional arguments (default: %s)"), | ||||
DEFAULT_NAMED)); | DEFAULT_NAMED), | ||||
strUsage += HelpMessageOpt( | false, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg( | |||||
"-rpcconnect=<ip>", | "-rpcconnect=<ip>", | ||||
strprintf(_("Send commands to node running on <ip> (default: %s)"), | strprintf(_("Send commands to node running on <ip> (default: %s)"), | ||||
DEFAULT_RPCCONNECT)); | DEFAULT_RPCCONNECT), | ||||
strUsage += HelpMessageOpt( | false, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg( | |||||
"-rpcport=<port>", | "-rpcport=<port>", | ||||
strprintf( | strprintf( | ||||
_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), | _("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), | ||||
defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort())); | defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()), | ||||
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start")); | false, OptionsCategory::OPTIONS); | ||||
strUsage += HelpMessageOpt("-rpcuser=<user>", | gArgs.AddArg("-rpcwait", _("Wait for RPC server to start"), false, | ||||
_("Username for JSON-RPC connections")); | OptionsCategory::OPTIONS); | ||||
strUsage += HelpMessageOpt("-rpcpassword=<pw>", | gArgs.AddArg("-rpcuser=<user>", _("Username for JSON-RPC connections"), | ||||
_("Password for JSON-RPC connections")); | false, OptionsCategory::OPTIONS); | ||||
strUsage += | gArgs.AddArg("-rpcpassword=<pw>", _("Password for JSON-RPC connections"), | ||||
HelpMessageOpt("-rpcclienttimeout=<n>", | false, OptionsCategory::OPTIONS); | ||||
strprintf(_("Timeout in seconds during HTTP requests, " | gArgs.AddArg("-rpcclienttimeout=<n>", | ||||
"or 0 for no timeout. (default: %d)"), | strprintf(_("Timeout in seconds during HTTP requests, or 0 " | ||||
DEFAULT_HTTP_CLIENT_TIMEOUT)); | "for no timeout. (default: %d)"), | ||||
DEFAULT_HTTP_CLIENT_TIMEOUT), | |||||
false, OptionsCategory::OPTIONS); | |||||
strUsage += HelpMessageOpt( | gArgs.AddArg( | ||||
"-stdinrpcpass", | "-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 " | "When combined with -stdin, the first line from standard " | ||||
"input is used for the RPC password."))); | "input is used for the RPC password.")), | ||||
strUsage += HelpMessageOpt( | false, OptionsCategory::OPTIONS); | ||||
"-stdin", _("Read extra arguments from standard input, one per line " | gArgs.AddArg("-stdin", | ||||
_("Read extra arguments from standard input, one per line " | |||||
"until EOF/Ctrl-D (recommended for sensitive information " | "until EOF/Ctrl-D (recommended for sensitive information " | ||||
"such as passphrases)")); | "such as passphrases)"), | ||||
strUsage += HelpMessageOpt( | false, OptionsCategory::OPTIONS); | ||||
"-rpcwallet=<walletname>", | gArgs.AddArg("-rpcwallet=<walletname>", | ||||
_("Send RPC for non-default wallet on RPC server (argument is wallet " | _("Send RPC for non-default wallet on RPC server (argument is " | ||||
"filename in bitcoind directory, required if bitcoind/-Qt runs with " | "wallet filename in bitcoind directory, required if " | ||||
"multiple wallets)")); | "bitcoind/-Qt runs with multiple wallets)"), | ||||
false, OptionsCategory::OPTIONS); | |||||
return strUsage; | |||||
} | } | ||||
////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////// | ||||
// | // | ||||
// Start | // Start | ||||
// | // | ||||
// | // | ||||
Show All 9 Lines | |||||
// | // | ||||
// This function returns either one of EXIT_ codes when it's expected to stop | // 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. | // the process or CONTINUE_EXECUTION when it's expected to continue further. | ||||
// | // | ||||
static int AppInitRPC(int argc, char *argv[]) { | static int AppInitRPC(int argc, char *argv[]) { | ||||
// | // | ||||
// Parameters | // Parameters | ||||
// | // | ||||
SetupCliArgs(); | |||||
gArgs.ParseParameters(argc, argv); | gArgs.ParseParameters(argc, argv); | ||||
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { | ||||
std::string strUsage = | std::string strUsage = | ||||
PACKAGE_NAME " RPC client version " + FormatFullVersion() + "\n"; | PACKAGE_NAME " RPC client version " + FormatFullVersion() + "\n"; | ||||
if (!gArgs.IsArgSet("-version")) { | if (!gArgs.IsArgSet("-version")) { | ||||
strUsage += "\n" | strUsage += "\n" | ||||
"Usage: bitcoin-cli [options] <command> [params] " | "Usage: bitcoin-cli [options] <command> [params] " | ||||
"Send command to " PACKAGE_NAME "\n" | "Send command to " PACKAGE_NAME "\n" | ||||
"or: bitcoin-cli [options] -named <command> " | "or: bitcoin-cli [options] -named <command> " | ||||
"[name=value]... Send command to " PACKAGE_NAME | "[name=value]... Send command to " PACKAGE_NAME | ||||
" (with named arguments)\n" | " (with named arguments)\n" | ||||
"or: bitcoin-cli [options] help " | "or: bitcoin-cli [options] help " | ||||
"List commands\n" | "List commands\n" | ||||
"or: bitcoin-cli [options] help <command> Get " | "or: bitcoin-cli [options] help <command> Get " | ||||
"help for a command\n"; | "help for a command\n"; | ||||
strUsage += "\n" + HelpMessageCli(); | strUsage += "\n" + gArgs.GetHelpMessage(); | ||||
} | } | ||||
fprintf(stdout, "%s", strUsage.c_str()); | fprintf(stdout, "%s", strUsage.c_str()); | ||||
if (argc < 2) { | if (argc < 2) { | ||||
fprintf(stderr, "Error: too few parameters\n"); | fprintf(stderr, "Error: too few parameters\n"); | ||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||||
▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines |