MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CommandLineRPC

Function CommandLineRPC

src/bitcoin-cli.cpp:449–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447}
448
449static int CommandLineRPC(int argc, char *argv[])
450{
451 std::string strPrint;
452 int nRet = 0;
453 try {
454 // Skip switches
455 while (argc > 1 && IsSwitchChar(argv[1][0])) {
456 argc--;
457 argv++;
458 }
459 std::string rpcPass;
460 if (gArgs.GetBoolArg("-stdinrpcpass", false)) {
461 if (!std::getline(std::cin, rpcPass)) {
462 throw std::runtime_error("-stdinrpcpass specified but failed to read from standard input");
463 }
464 gArgs.ForceSetArg("-rpcpassword", rpcPass);
465 }
466 std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
467 if (gArgs.GetBoolArg("-stdin", false)) {
468 // Read one arg per line from stdin and append
469 std::string line;
470 while (std::getline(std::cin, line)) {
471 args.push_back(line);
472 }
473 }
474 std::unique_ptr<BaseRequestHandler> rh;
475 std::string method;
476 if (gArgs.GetBoolArg("-getinfo", false)) {
477 rh.reset(new GetinfoRequestHandler());
478 method = "";
479 } else {
480 rh.reset(new DefaultRequestHandler());
481 if (args.size() < 1) {
482 throw std::runtime_error("too few parameters (need at least command)");
483 }
484 method = args[0];
485 args.erase(args.begin()); // Remove trailing method name from arguments vector
486 }
487
488 // Execute and handle connection failures with -rpcwait
489 const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
490 do {
491 try {
492 const UniValue reply = CallRPC(rh.get(), method, args);
493
494 // Parse reply
495 const UniValue& result = find_value(reply, "result");
496 const UniValue& error = find_value(reply, "error");
497
498 if (!error.isNull()) {
499 // Error
500 int code = error["code"].get_int();
501 if (fWait && code == RPC_IN_WARMUP)
502 throw CConnectionFailed("server in warmup");
503 strPrint = "error: " + error.write();
504 nRet = abs(code);
505 if (error.isObject())
506 {

Callers 1

mainFunction · 0.85

Calls 15

IsSwitchCharFunction · 0.85
CConnectionFailedClass · 0.85
MilliSleepFunction · 0.85
PrintExceptionContinueFunction · 0.85
GetBoolArgMethod · 0.80
ForceSetArgMethod · 0.80
getMethod · 0.80
isNullMethod · 0.80
get_intMethod · 0.80
isObjectMethod · 0.80
isStrMethod · 0.80
isNumMethod · 0.80

Tested by

no test coverage detected