aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-02-24 11:33:08 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-02-24 11:33:25 +0100
commit8b958ab15b8c187dd2041575f7115cbac7591166 (patch)
treee3c1287c675572f5d1d195b7b90a5b1fd3382bda /src
parenta08c41dfc23234064da322159652b44684df9375 (diff)
parentf22f14c65bb9fba946e5039132a4c0b01b0c02ce (diff)
Merge #7550: rpc: Input-from-stdin mode for bitcoin-cli
f22f14c doc: mention bitcoin-cli -stdin in release notes (Wladimir J. van der Laan) 92bcca3 rpc: Input-from-stdin mode for bitcoin-cli (Wladimir J. van der Laan)
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-cli.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 34980d9ca1..49935699fd 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -43,6 +43,7 @@ std::string HelpMessageCli()
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout during HTTP requests (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
+ strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases)"));
return strUsage;
}
@@ -232,15 +233,17 @@ int CommandLineRPC(int argc, char *argv[])
argc--;
argv++;
}
-
- // Method
- if (argc < 2)
- throw runtime_error("too few parameters");
- string strMethod = argv[1];
-
- // Parameters default to strings
- std::vector<std::string> strParams(&argv[2], &argv[argc]);
- UniValue params = RPCConvertValues(strMethod, strParams);
+ std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
+ if (GetBoolArg("-stdin", false)) {
+ // Read one arg per line from stdin and append
+ std::string line;
+ while (std::getline(std::cin,line))
+ args.push_back(line);
+ }
+ if (args.size() < 1)
+ throw runtime_error("too few parameters (need at least command)");
+ std::string strMethod = args[0];
+ UniValue params = RPCConvertValues(strMethod, std::vector<std::string>(args.begin()+1, args.end()));
// Execute and handle connection failures with -rpcwait
const bool fWait = GetBoolArg("-rpcwait", false);