Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-cli.cpp
Show All 14 Lines | |||||
#include <support/events.h> | #include <support/events.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <event2/buffer.h> | #include <event2/buffer.h> | ||||
#include <event2/keyvalq_struct.h> | #include <event2/keyvalq_struct.h> | ||||
#include <compat/stdin.h> | |||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <functional> | #include <functional> | ||||
#include <memory> | #include <memory> | ||||
#include <tuple> | #include <tuple> | ||||
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr; | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | gArgs.AddArg("-rpcclienttimeout=<n>", | ||||
strprintf("Timeout in seconds during HTTP requests, or 0 for " | strprintf("Timeout in seconds during HTTP requests, or 0 for " | ||||
"no timeout. (default: %d)", | "no timeout. (default: %d)", | ||||
DEFAULT_HTTP_CLIENT_TIMEOUT), | DEFAULT_HTTP_CLIENT_TIMEOUT), | ||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg("-stdinrpcpass", | gArgs.AddArg("-stdinrpcpass", | ||||
"Read RPC password from standard input as a single " | "Read RPC password from standard input as a single " | ||||
"line. When combined with -stdin, the first line " | "line. When combined with -stdin, the first line " | ||||
"from standard input is used for the RPC password.", | "from standard input is used for the RPC password. When " | ||||
"combined with -stdinwalletpassphrase, -stdinrpcpass " | |||||
"consumes the first line, and -stdinwalletpassphrase " | |||||
"consumes the second.", | |||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | |||||
gArgs.AddArg("-stdinwalletpassphrase", | |||||
"Read wallet passphrase from standard input as a single " | |||||
"line. When combined with -stdin, the first line " | |||||
"from standard input is used for the wallet passphrase.", | |||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg("-stdin", | gArgs.AddArg("-stdin", | ||||
"Read extra arguments from standard input, one per line until " | "Read extra arguments from standard input, one per line until " | ||||
"EOF/Ctrl-D (recommended for sensitive information such as " | "EOF/Ctrl-D (recommended for sensitive information such as " | ||||
"passphrases). When combined with -stdinrpcpass, the first " | "passphrases). When combined with -stdinrpcpass, the first " | ||||
"line from standard input is used for the RPC password.", | "line from standard input is used for the RPC password.", | ||||
ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||||
gArgs.AddArg( | gArgs.AddArg( | ||||
▲ Show 20 Lines • Show All 405 Lines • ▼ Show 20 Lines | static int CommandLineRPC(int argc, char *argv[]) { | ||||
try { | try { | ||||
// Skip switches | // Skip switches | ||||
while (argc > 1 && IsSwitchChar(argv[1][0])) { | while (argc > 1 && IsSwitchChar(argv[1][0])) { | ||||
argc--; | argc--; | ||||
argv++; | argv++; | ||||
} | } | ||||
std::string rpcPass; | std::string rpcPass; | ||||
if (gArgs.GetBoolArg("-stdinrpcpass", false)) { | if (gArgs.GetBoolArg("-stdinrpcpass", false)) { | ||||
NO_STDIN_ECHO(); | |||||
if (!StdinReady()) { | |||||
fputs("RPC password> ", stderr); | |||||
fflush(stderr); | |||||
} | |||||
if (!std::getline(std::cin, rpcPass)) { | if (!std::getline(std::cin, rpcPass)) { | ||||
throw std::runtime_error("-stdinrpcpass specified but failed " | throw std::runtime_error("-stdinrpcpass specified but failed " | ||||
"to read from standard input"); | "to read from standard input"); | ||||
} | } | ||||
gArgs.ForceSetArg("-rpcpassword", rpcPass); | gArgs.ForceSetArg("-rpcpassword", rpcPass); | ||||
} | } | ||||
std::vector<std::string> args = | std::vector<std::string> args = | ||||
std::vector<std::string>(&argv[1], &argv[argc]); | std::vector<std::string>(&argv[1], &argv[argc]); | ||||
if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { | |||||
NO_STDIN_ECHO(); | |||||
std::string walletPass; | |||||
if (args.size() < 1 || | |||||
args[0].substr(0, 16) != "walletpassphrase") { | |||||
throw std::runtime_error( | |||||
"-stdinwalletpassphrase is only applicable for " | |||||
"walletpassphrase(change)"); | |||||
} | |||||
if (!StdinReady()) { | |||||
fputs("Wallet passphrase> ", stderr); | |||||
fflush(stderr); | |||||
} | |||||
if (!std::getline(std::cin, walletPass)) { | |||||
throw std::runtime_error("-stdinwalletpassphrase specified but " | |||||
"failed to read from standard input"); | |||||
} | |||||
args.insert(args.begin() + 1, walletPass); | |||||
} | |||||
if (gArgs.GetBoolArg("-stdin", false)) { | if (gArgs.GetBoolArg("-stdin", false)) { | ||||
// Read one arg per line from stdin and append | // Read one arg per line from stdin and append | ||||
std::string line; | std::string line; | ||||
while (std::getline(std::cin, line)) { | while (std::getline(std::cin, line)) { | ||||
args.push_back(line); | args.push_back(line); | ||||
} | } | ||||
} | } | ||||
std::unique_ptr<BaseRequestHandler> rh; | std::unique_ptr<BaseRequestHandler> rh; | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |