MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ParseGetInfoResult

Function ParseGetInfoResult

src/bitcoin-cli.cpp:1406–1523  ·  view source on GitHub ↗

* ParseGetInfoResult takes in -getinfo result in UniValue object and parses it * into a user friendly UniValue string to be printed on the console. * @param[out] result Reference to UniValue result containing the -getinfo output. */

Source from the content-addressed store, hash-verified

1404 * @param[out] result Reference to UniValue result containing the -getinfo output.
1405 */
1406static void ParseGetInfoResult(UniValue& result)
1407{
1408 if (!result.find_value("error").isNull()) return;
1409
1410 std::string RESET, GREEN, BLUE, YELLOW, MAGENTA, CYAN;
1411 bool should_colorize = false;
1412
1413#ifndef WIN32
1414 if (isatty(fileno(stdout))) {
1415 // By default, only print colored text if OS is not WIN32 and stdout is connected to a terminal.
1416 should_colorize = true;
1417 }
1418#endif
1419
1420 {
1421 const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)};
1422 if (color == "always") {
1423 should_colorize = true;
1424 } else if (color == "never") {
1425 should_colorize = false;
1426 } else if (color != "auto") {
1427 throw std::runtime_error("Invalid value for -color option. Valid values: always, auto, never.");
1428 }
1429 }
1430
1431 if (should_colorize) {
1432 RESET = "\x1B[0m";
1433 GREEN = "\x1B[32m";
1434 BLUE = "\x1B[34m";
1435 YELLOW = "\x1B[33m";
1436 MAGENTA = "\x1B[35m";
1437 CYAN = "\x1B[36m";
1438 }
1439
1440 std::string result_string = strprintf("%sChain: %s%s\n", BLUE, result["chain"].getValStr(), RESET);
1441 result_string += strprintf("Blocks: %s\n", result["blocks"].getValStr());
1442 result_string += strprintf("Headers: %s\n", result["headers"].getValStr());
1443
1444 const double ibd_progress{result["verificationprogress"].get_real()};
1445 std::string ibd_progress_bar;
1446 // Display the progress bar only if IBD progress is less than 99%
1447 if (ibd_progress < 0.99) {
1448 GetProgressBar(ibd_progress, ibd_progress_bar);
1449 // Add padding between progress bar and IBD progress
1450 ibd_progress_bar += " ";
1451 }
1452
1453 result_string += strprintf("Verification progress: %s%.4f%%\n", ibd_progress_bar, ibd_progress * 100);
1454 result_string += strprintf("Difficulty: %s\n\n", result["difficulty"].getValStr());
1455
1456 result_string += strprintf(
1457 "%sNetwork: in %s, out %s, total %s%s\n",
1458 GREEN,
1459 result["connections"]["in"].getValStr(),
1460 result["connections"]["out"].getValStr(),
1461 result["connections"]["total"].getValStr(),
1462 RESET);
1463 result_string += strprintf("Version: %s\n", result["version"].getValStr());

Callers 1

CommandLineRPCFunction · 0.85

Calls 13

GetProgressBarFunction · 0.85
JoinFunction · 0.85
isNullMethod · 0.80
GetArgMethod · 0.80
get_realMethod · 0.80
findMethod · 0.80
setStrMethod · 0.80
emptyMethod · 0.45
containsMethod · 0.45
push_backMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected