Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
rpc: Input-from-stdin mode for bitcoin-cli #7550
Conversation
laanwj
added
the
RPC/REST/ZMQ
label
Feb 17, 2016
|
Brilliant idea! pavel$ echo -e "getblockhash\n0" | bitcoin-7550/src/bitcoin-cli -stdin
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
pavel$ |
laanwj
added
the
Feature
label
Feb 17, 2016
|
Nice! |
jonasschnelli
commented on the diff
Feb 19, 2016
| @@ -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)) |
jonasschnelli
Member
|
|
Tested ACK c97198db769954c4ad2b57eaf7e5335578badc00 Post-merge actions: add to the docs/release notes, maybe add a little test script (though, not sure if we have a test entry point for bitcoin-cli at all). |
|
Re-ACK 92bcca3 |
laanwj commentedFeb 17, 2016
Implements #7442 by adding an option
-stdinwhich reads additional arguments from standard in, one per line.For example
This is the simplest implementation and avoids escaping issues by using newline as separator instead of space, I first had another implementation: laanwj/bitcoin@1f73b8e that reuses
parseCommandLinefrom the GUI debug console, but I think this is more useful in practice as most use of cli is probably script-driven.