| 1549 | } |
| 1550 | |
| 1551 | static int CommandLineRPC(int argc, char *argv[]) |
| 1552 | { |
| 1553 | std::string strPrint; |
| 1554 | int nRet = 0; |
| 1555 | try { |
| 1556 | // Skip switches |
| 1557 | while (argc > 1 && IsSwitchChar(argv[1][0])) { |
| 1558 | argc--; |
| 1559 | argv++; |
| 1560 | } |
| 1561 | std::string rpcPass; |
| 1562 | if (gArgs.GetBoolArg("-stdinrpcpass", false)) { |
| 1563 | NO_STDIN_ECHO(); |
| 1564 | if (!StdinReady()) { |
| 1565 | fputs("RPC password> ", stderr); |
| 1566 | fflush(stderr); |
| 1567 | } |
| 1568 | if (!std::getline(std::cin, rpcPass)) { |
| 1569 | throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input"); |
| 1570 | } |
| 1571 | if (StdinTerminal()) { |
| 1572 | fputc('\n', stdout); |
| 1573 | } |
| 1574 | gArgs.ForceSetArg("-rpcpassword", rpcPass); |
| 1575 | } |
| 1576 | std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]); |
| 1577 | if (gArgs.GetBoolArg("-stdinwalletpassphrase", false)) { |
| 1578 | NO_STDIN_ECHO(); |
| 1579 | std::string walletPass; |
| 1580 | if (args.size() < 1 || !args[0].starts_with("walletpassphrase")) { |
| 1581 | throw std::runtime_error("-stdinwalletpassphrase is only applicable for walletpassphrase(change)"); |
| 1582 | } |
| 1583 | if (!StdinReady()) { |
| 1584 | fputs("Wallet passphrase> ", stderr); |
| 1585 | fflush(stderr); |
| 1586 | } |
| 1587 | if (!std::getline(std::cin, walletPass)) { |
| 1588 | throw std::runtime_error("-stdinwalletpassphrase specified but failed to read from standard input"); |
| 1589 | } |
| 1590 | if (StdinTerminal()) { |
| 1591 | fputc('\n', stdout); |
| 1592 | } |
| 1593 | args.insert(args.begin() + 1, walletPass); |
| 1594 | } |
| 1595 | if (gArgs.GetBoolArg("-stdin", false)) { |
| 1596 | // Read one arg per line from stdin and append |
| 1597 | std::string line; |
| 1598 | while (std::getline(std::cin, line)) { |
| 1599 | args.push_back(line); |
| 1600 | } |
| 1601 | if (StdinTerminal()) { |
| 1602 | fputc('\n', stdout); |
| 1603 | } |
| 1604 | } |
| 1605 | gArgs.CheckMultipleCLIArgs(); |
| 1606 | std::unique_ptr<BaseRequestHandler> rh; |
| 1607 | std::string method; |
| 1608 | if (gArgs.GetBoolArg("-getinfo", false)) { |
no test coverage detected