| 1092 | } |
| 1093 | |
| 1094 | static int CommandLineRPC(int argc, char *argv[]) |
| 1095 | { |
| 1096 | std::string strPrint; |
| 1097 | int nRet = 0; |
| 1098 | try { |
| 1099 | // Skip switches |
| 1100 | while (argc > 1 && IsSwitchChar(argv[1][0])) { |
| 1101 | argc--; |
| 1102 | argv++; |
| 1103 | } |
| 1104 | std::string rpcPass; |
| 1105 | if (gArgs.GetBoolArg("-stdinrpcpass", false)) { |
| 1106 | NO_STDIN_ECHO(); |
| 1107 | if (!StdinReady()) { |
| 1108 | fputs("RPC password> ", stderr); |
| 1109 | fflush(stderr); |
| 1110 | } |
| 1111 | if (!std::getline(std::cin, rpcPass)) { |
| 1112 | throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input"); |
| 1113 | } |
| 1114 | if (StdinTerminal()) { |
| 1115 | fputc('\n', stdout); |
| 1116 | } |
| 1117 | gArgs.ForceSetArg("-rpcpassword", rpcPass); |
| 1118 | } |
| 1119 | std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]); |
| 1120 | if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { |
| 1121 | NO_STDIN_ECHO(); |
| 1122 | std::string walletPass; |
| 1123 | if (args.size() < 1 || args[0].substr(0, 16) != "walletpassphrase") { |
| 1124 | throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)"); |
| 1125 | } |
| 1126 | if (!StdinReady()) { |
| 1127 | fputs("Wallet passphrase> ", stderr); |
| 1128 | fflush(stderr); |
| 1129 | } |
| 1130 | if (!std::getline(std::cin, walletPass)) { |
| 1131 | throw std::runtime_error("-stdinwalletpassphrase specified but failed to read from standard input"); |
| 1132 | } |
| 1133 | if (StdinTerminal()) { |
| 1134 | fputc('\n', stdout); |
| 1135 | } |
| 1136 | args.insert(args.begin() + 1, walletPass); |
| 1137 | } |
| 1138 | if (gArgs.GetBoolArg("-stdin", false)) { |
| 1139 | // Read one arg per line from stdin and append |
| 1140 | std::string line; |
| 1141 | while (std::getline(std::cin, line)) { |
| 1142 | args.push_back(line); |
| 1143 | } |
| 1144 | if (StdinTerminal()) { |
| 1145 | fputc('\n', stdout); |
| 1146 | } |
| 1147 | } |
| 1148 | std::unique_ptr<BaseRequestHandler> rh; |
| 1149 | std::string method; |
| 1150 | if (gArgs.IsArgSet("-getinfo")) { |
| 1151 | rh.reset(new GetinfoRequestHandler()); |
no test coverage detected