aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSamuel Dobson <dobsonsa68@gmail.com>2021-08-10 22:10:56 +1200
committerSamuel Dobson <dobsonsa68@gmail.com>2021-08-10 22:26:10 +1200
commitce0913148b687310f2933397d0bbe4bd014c178e (patch)
tree6c10a197459bbbcafebb3b4dcfc8bb35a8ef33d0 /src
parent8193294caba03b996370873db79cf4fc22a1e95b (diff)
parentb851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 (diff)
Merge bitcoin/bitcoin#22547: cli: Add progress bar for -getinfo
b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 cli: Add progress bar for -getinfo (klementtan) Pull request description: Add a progress bar for the `Verification progress` attribute in `-getinfo` when verification progress `< 99%`. ![image](https://user-images.githubusercontent.com/49265907/127897458-27d8aaa9-7893-4665-9c40-36389a8d9cbb.png) **Motivation**: * Improve user-friendliness of `-getinfo` * Can be useful with `watch -n 1 bitcoin-cli -getinfo`(suggested by theStack [below](https://github.com/bitcoin/bitcoin/pull/22547#issuecomment-887488172)) * The progress bar is only display when are still syncing to tip(verification progress `< 99%`) **Reviewing** If your verification progress is `> 99%` you can restart the verification progress with ```shell $ ./src/bitcoind -reindex $./src/bitcoin-cli -getinfo ``` ACKs for top commit: prayank23: reACK https://github.com/bitcoin/bitcoin/commit/b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 theStack: re-ACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 🍹 Zero-1729: re-tACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 (re-tested, works as expected 🍾) jonatack: ACK b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 lsilva01: Tested ACK https://github.com/bitcoin/bitcoin/pull/22547/commits/b851a92c06cd1d6a40a5527ae39d60ae7fa33fb9 on mainnet and signet on Ubuntu 20.04. Tree-SHA512: 2046d812e3c4623c6cc3ed4c24f2daaa92ba12cd181fa21626b782743890c2373be3175cff1441a7ba37295b6d5818368deea90d483959875c22f7ad9b601a20
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-cli.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 1ec6411e32..bc0af6398c 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -885,6 +885,29 @@ static void GetWalletBalances(UniValue& result)
}
/**
+ * GetProgressBar contructs a progress bar with 5% intervals.
+ *
+ * @param[in] progress The proportion of the progress bar to be filled between 0 and 1.
+ * @param[out] progress_bar String representation of the progress bar.
+ */
+static void GetProgressBar(double progress, std::string& progress_bar)
+{
+ if (progress < 0 || progress > 1) return;
+
+ static constexpr double INCREMENT{0.05};
+ static const std::string COMPLETE_BAR{"\u2592"};
+ static const std::string INCOMPLETE_BAR{"\u2591"};
+
+ for (int i = 0; i < progress / INCREMENT; ++i) {
+ progress_bar += COMPLETE_BAR;
+ }
+
+ for (int i = 0; i < (1 - progress) / INCREMENT; ++i) {
+ progress_bar += INCOMPLETE_BAR;
+ }
+}
+
+/**
* 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.
@@ -926,7 +949,17 @@ static void ParseGetInfoResult(UniValue& result)
std::string result_string = strprintf("%sChain: %s%s\n", BLUE, result["chain"].getValStr(), RESET);
result_string += strprintf("Blocks: %s\n", result["blocks"].getValStr());
result_string += strprintf("Headers: %s\n", result["headers"].getValStr());
- result_string += strprintf("Verification progress: %.4f%%\n", result["verificationprogress"].get_real() * 100);
+
+ const double ibd_progress{result["verificationprogress"].get_real()};
+ std::string ibd_progress_bar;
+ // Display the progress bar only if IBD progress is less than 99%
+ if (ibd_progress < 0.99) {
+ GetProgressBar(ibd_progress, ibd_progress_bar);
+ // Add padding between progress bar and IBD progress
+ ibd_progress_bar += " ";
+ }
+
+ result_string += strprintf("Verification progress: %s%.4f%%\n", ibd_progress_bar, ibd_progress * 100);
result_string += strprintf("Difficulty: %s\n\n", result["difficulty"].getValStr());
result_string += strprintf(