-
Notifications
You must be signed in to change notification settings - Fork 38.7k
cli: Improve -getinfo return format #21832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones: If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
🕵️ @jonatack has been requested to review this pull request as specified in the REVIEWERS file. |
|
Concept ACK. Quick test below on signet. Build is clean, only skimmed the code for now. Ideas:
|
|
@jonatack
|
|
I think this is nice. It looks better, is more user friendly, and at the same time discourages parsing the output in scripts and such (which is good because it is not intended as a stable interface). |
|
Added check to not print ansi colour code if running on |
|
Looks good to me now. I think it makes sense to squash these commits before merge, as they incrementally change the same code. |
|
@laanwj Roger that. Squashed all the commits to a single commit. Not sure why the last CI task is failing tho. Anyone have a clue? |
d96b160 to
c271d17
Compare
|
Thanks!
Seems to be solved now. We have transient issues with the CI quite often, unfortunately. |
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick skim of the code, waiting on the build to test.
|
Approach ACK Some questions (not sure they are good ideas!) The Bitcoin symbols are neat but I'm not sure they are needed...or maybe instead add just one symbol in parentheses after "Balances" in the header, e.g. Balances (B)...or insert a space between them and the balance? Should the field names be capitalized? e.g. s/verification progress/Verification progress/? Maybe hoist "chain: signet" to the header and shorten it to chain? e.g. "Chain: signet", thereby removing a line...and if so, should that section be at the top, before the Network section? |
|
Updated the PR to according @jonatack' comments
|
|
Test of f93b021472 What do you think about
|
|
Oh, and if you need some sBTC (signet coins) for testing, here's a faucet: https://signetfaucet.com (I can send you some too, if you need). |
eb03366 to
ed7feb4
Compare
|
Updated ed7feb4 with the following changes:
@jonatack I hard-coded a fake wallet to simulate and test a large balance wallet but if you don't mind sending me some sBTC to test it without hard-coding a wallet that would be great(address |
|
Sent you some signet coins (wow, the faucet used to be 10 sBTC and now it's max .01). Thanks for updating! Looking pretty good. I think the balances alignment should based on the decimal point (apologies, I was unclear) which might require padding spaces after the balance as well if there are fewer than 8 digits after the decimal point (I thought there were always 8). And maybe we can omit the |
|
Got it! Thanks for sending it to me and replying to me so quickly. My apologies the amount was hardcoded by me and I added fewer decimal places than what it would actually have. Here is the updated screenshot of what it would look like when one wallet contains "longer" balance than others
Yup I agree Edit: |
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lightly-tested re-ACK 14cb2e0fe1384f89b4c9ca70751e6676f438b7a5 with suggested changes to the new -color help (feel free to ignore the code suggestions)
diff
@@ -52,6 +52,9 @@ static constexpr int8_t UNKNOWN_NETWORK{-1};
/** Default number of blocks to generate for RPC generatetoaddress. */
static const std::string DEFAULT_NBLOCKS = "1";
+/** Default -color setting. */
+static const std::string DEFAULT_COLOR_SETTING{"auto"};
+
static void SetupCliArgs(ArgsManager& argsman)
{
SetupHelpOptions(argsman);
@@ -70,6 +73,7 @@ static void SetupCliArgs(ArgsManager& argsman)
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 4 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
SetupChainParamsBaseOptions(argsman);
+ argsman.AddArg("-color=<when>", strprintf("Color setting for CLI output (default: %s). Valid values: always, auto (add color codes when standard output is connected to a terminal and OS is not WIN32), never.", DEFAULT_COLOR_SETTING), ArgsManager::ALLOW_STRING, OptionsCategory::OPTIONS);
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-rpcclienttimeout=<n>", strprintf("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)", DEFAULT_HTTP_CLIENT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-rpcconnect=<ip>", strprintf("Send commands to node running on <ip> (default: %s)", DEFAULT_RPCCONNECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -82,7 +86,6 @@ static void SetupCliArgs(ArgsManager& argsman)
argsman.AddArg("-stdin", "Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases). When combined with -stdinrpcpass, the first line from standard input is used for the RPC password.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password. When combined with -stdinwalletpassphrase, -stdinrpcpass consumes the first line, and -stdinwalletpassphrase consumes the second.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-stdinwalletpassphrase", "Read wallet passphrase from standard input as a single line. When combined with -stdin, the first line from standard input is used for the wallet passphrase.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- argsman.AddArg("-color=<when>", "Enable key information from CLI response to be displayed with color. With \"-color=auto\", bitcoin-cli will only emit color codes when standard output is connected to a terminal and OS is not WIN32. \"when\" can be \"never\", \"always\", or \"auto\"(default).", ArgsManager::ALLOW_STRING, OptionsCategory::OPTIONS);
}
/** libevent event log callback */
@@ -895,8 +898,7 @@ static void ParseGetInfoResult(UniValue& result)
#endif
if (gArgs.IsArgSet("-color")) {
- // Override default should_colorize value if -color is set.
- std::string color = gArgs.GetArg("-color", "auto");
+ const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)};
if (color == "always") {
should_colorize = true;
} else if (color == "never") {|
14cb2e0 to 658ab9c:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 658ab9caa3423aa7f50ae7bd0ee7ebb50f0114b0 per git diff 14cb2e0 658ab9c and lightly re-tested rebased to master on each chain and with various wallet configs.
New -color option help
$ ./src/bitcoin-cli -h | grep -A1 color
-color=<when>
Color setting for CLI output (default: auto). Valid values: always, auto
(add color codes when standard output is connected to a terminal
and OS is not WIN32), never.
New error
$ ./src/bitcoin-cli -regtest -color=foo -getinfo
error: Invalid value for -color option. Valid values: always, auto, never.
9062edd to
d525177
Compare
|
re-ACK d525177aba60e996481007989422280f9c191f15 per Only change is addressing feedback on 2 test logging touch-ups. |
|
658ab9c to 62aaff1: resolved comments from reviewers regarding logging and better handling of |
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 62aaff178a665d757b604ee4a90556242c1135d3 🍪
Verified that the following changes since my previous ACK are OK: stricter -color argument handling with a corresponding test, plus minor style changes in the -color help and the test log messages 👌
|
re-ACK 62aaff178a665d757b604ee4a90556242c1135d3 per |
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rebase
|
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
theStack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK a37e29d
Verified via git range-diff 62aaff17...a37e29d3 that the latest change since my last ACK is only rebase-related.
|
Congrats @klementtan, well-deserved. |
|
This PR seems to be merged, but is still open. Another GitHub problem I guess? 🤔 |











Overview
Description This PR changes the return format of
-getinfoRationale
-getinfomore user-friendlyFixes: Issue 17314(Not linking issue to prevent it from closing)
Return Format
Coloring
The following lines would be colored to better show the differences between the various
-getinfocomponents. However, this will not apply forWIN32(ANSI code not supported) and users that connect thestdoutto a non-terminal process.Chain: ...: BLUE(\x1B[34m)Network: ...: GREEN(\x1B[32m)Wallet: ...: MAGENTA(\x1B[35m)Balance: ...CYAN(\x1B[36m)Balances: ...CYAN(\x1B[36m)Warnings: ...Yellow(\x1B[33m)Screenshots
No wallet loaded:

Single wallet loaded

Multi wallet loaded

Reviewing Notes
Testing Scenarios
1. No wallet loaded
./src/bitcoin-cli unloadwallet "YOUR_WALLETNAME"./src/bitcoin-cli -getinfo.chainandnetworksegment2. Single wallet loaded
-rpcwalletis set(Load wallet with./src/bitcoin-cli loadwallet "YOUR_WALLETNAME")./src/bitcoin-cli -rpcwallet="YOUR_WALLETNAME" -getinfo(Load wallet with./src/bitcoin-cli loadwallet "YOUR_WALLETNAME")chain,network,walletandbalancesegment3. Multiple wallet loaded
./src/bitcoin-cli loadwallet "YOUR_WALLETNAME")./src/bitcoin-cli -getinfochain,networkandbalancessegmentImplementation
Current Flow
GetinfoRequestHandleris instantiatedConnectAndCallRPCis called withGetinfoRequestHandler. It returnsUniValue::VOBJ result-rpcwalletwallet is not set,GetWalletBalancesis called with a pointer toresultas a parameter. It adds the balances for all the wallets toresultNew Flow
GetinfoRequestHandleris instantiatedConnectAndCallRPCis called withGetinfoRequestHandler. It returnsUniValue::VOBJ result-rpcwalletwallet is not set,GetWalletBalancesis called with a pointer toresultas a parameter. It adds the balances for all the wallets toresultParseGetInfoResultis called withresultas parameter. It converts results type fromUniValue::VOBJtoUniValue::VSTRaccording to the format stated above.