Skip to content

Commit f1da40c

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#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)
1 parent f840708 commit f1da40c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/dash-cli.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ std::string HelpMessageCli()
4141
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
4242
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
4343
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout during HTTP requests (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
44+
strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases)"));
4445

4546
return strUsage;
4647
}
@@ -243,15 +244,17 @@ int CommandLineRPC(int argc, char *argv[])
243244
argc--;
244245
argv++;
245246
}
246-
247-
// Method
248-
if (argc < 2)
249-
throw runtime_error("too few parameters");
250-
string strMethod = argv[1];
251-
252-
// Parameters default to strings
253-
std::vector<std::string> strParams(&argv[2], &argv[argc]);
254-
UniValue params = RPCConvertValues(strMethod, strParams);
247+
std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
248+
if (GetBoolArg("-stdin", false)) {
249+
// Read one arg per line from stdin and append
250+
std::string line;
251+
while (std::getline(std::cin,line))
252+
args.push_back(line);
253+
}
254+
if (args.size() < 1)
255+
throw runtime_error("too few parameters (need at least command)");
256+
std::string strMethod = args[0];
257+
UniValue params = RPCConvertValues(strMethod, std::vector<std::string>(args.begin()+1, args.end()));
255258

256259
// Execute and handle connection failures with -rpcwait
257260
const bool fWait = GetBoolArg("-rpcwait", false);

0 commit comments

Comments
 (0)