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

Function CommandLineRPC

src/bitcoin-cli.cpp:244–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242}
243
244int CommandLineRPC(int argc, char *argv[])
245{
246 string strPrint;
247 int nRet = 0;
248 try {
249 // Skip switches
250 while (argc > 1 && IsSwitchChar(argv[1][0])) {
251 argc--;
252 argv++;
253 }
254
255 // Method
256 if (argc < 2)
257 throw runtime_error("too few parameters");
258 string strMethod = argv[1];
259
260 // Parameters default to strings
261 std::vector<std::string> strParams(&argv[2], &argv[argc]);
262 UniValue params = RPCConvertValues(strMethod, strParams);
263
264 // Execute and handle connection failures with -rpcwait
265 const bool fWait = GetBoolArg("-rpcwait", false);
266 do {
267 try {
268 const UniValue reply = CallRPC(strMethod, params);
269
270 // Parse reply
271 const UniValue& result = find_value(reply, "result");
272 const UniValue& error = find_value(reply, "error");
273
274 if (!error.isNull()) {
275 // Error
276 int code = error["code"].get_int();
277 if (fWait && code == RPC_IN_WARMUP)
278 throw CConnectionFailed("server in warmup");
279 strPrint = "error: " + error.write();
280 nRet = abs(code);
281 } else {
282 // Result
283 if (result.isNull())
284 strPrint = "";
285 else if (result.isStr())
286 strPrint = result.get_str();
287 else
288 strPrint = result.write(2);
289 }
290 // Connection succeeded, no need to retry.
291 break;
292 }
293 catch (const CConnectionFailed&) {
294 if (fWait)
295 MilliSleep(1000);
296 else
297 throw;
298 }
299 } while (fWait);
300 }
301 catch (const boost::thread_interrupted&) {

Callers 1

mainFunction · 0.85

Calls 12

IsSwitchCharFunction · 0.85
RPCConvertValuesFunction · 0.85
GetBoolArgFunction · 0.85
CConnectionFailedClass · 0.85
MilliSleepFunction · 0.85
PrintExceptionContinueFunction · 0.85
get_intMethod · 0.80
isStrMethod · 0.80
get_strMethod · 0.80
CallRPCFunction · 0.70
isNullMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected