You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a37e29d cli: Implement human readable -getinfo. (Klement Tan)
Pull request description:
# Overview
**Description** This PR changes the return format of `-getinfo`
**Rationale**
- make `-getinfo` more user-friendly
- uses less vertical screen space.
Fixes: Issue 17314(Not linking issue to prevent it from closing)
> Alternative, more human-friendly, format besides JSON? Colors, progress bars
### Return Format
```bash
// Data from getblockchaininfo
Chain: [getblockchaininfo.chain]
Blocks: [getblockchaininfo.blocks]
Headers: [getblockchaininfo.headers]
Verification progress: [getblockchaininfo.verificationprogress]
Difficulty: [getblockchaininfo.difficulty]
# Data from getnetworkinfo
Network: in [getnetworkinfo.connections_in], out [getnetworkinfo.connections_out], total [getnetworkinfo.connections]
Version: [getnetworkinfo.version]
Time offset (s): [getnetworkinfo.timeoffset]
Proxy: [getnetworkinfo.proxy] // "N/A" if no proxy
Min tx relay fee rate (BTC/kvB): [getnetworkinfo.relayfee]
# Data from getwalletinfo. Will only be present when a single wallet is loaded
Wallet: [getnetworkinfo.walletname] // "" if walletname is empty(default wallet)
Keypool size: [getnetworkinfo.keypoolsize]
Unlocked until: [getnetworkinfo.unlocked_until]
Transaction fee rate (-paytxfee) (BTC/kvB): [getnetworkinfo.paytxfee]
# Data from getbalances. Will only be present when a single wallet is loaded
Balance: [getbalances.mine.trusted]
# Data from listwallets then getbalances for each wallet. Will only be present for multiple wallets loaded
Balances
[getbalances.mine.trusted] [listwallets[i]] // Right justify on balance
Warnings: [getnetworkinfo.warnings]
```
#### Coloring
The following lines would be colored to better show the differences between the various `-getinfo` components. However, this will not apply for `WIN32`(ANSI code not supported) and users that connect the `stdout` to 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**
- When there no wallets are loaded(Unload wallet with `./src/bitcoin-cli unloadwallet "YOUR_WALLETNAME"`
- Test with `./src/bitcoin-cli -getinfo`.
- Should only display `chain` and `network` segment
**2. Single wallet loaded**
- When only a single wallet loaded or `-rpcwallet` is set(Load wallet with `./src/bitcoin-cli loadwallet "YOUR_WALLETNAME"`)
- Test with `./src/bitcoin-cli -rpcwallet="YOUR_WALLETNAME" -getinfo`(Load wallet with `./src/bitcoin-cli loadwallet "YOUR_WALLETNAME"`)
- Should only display `chain`, `network`, `wallet` and `balance` segment
**3. Multiple wallet loaded**
- When there are multiple wallets loaded(Load wallet with `./src/bitcoin-cli loadwallet "YOUR_WALLETNAME"`)
- Test with `./src/bitcoin-cli -getinfo`
- Should only display `chain`, `network` and `balances` segment
## Implementation
**Current Flow**
1. `GetinfoRequestHandler` is instantiated
2. `ConnectAndCallRPC` is called with `GetinfoRequestHandler`. It returns `UniValue::VOBJ result`
3. If `-rpcwallet` wallet is not set, `GetWalletBalances` is called with a pointer to `result` as a parameter. It adds the balances for all the wallets to `result`
**New Flow**
1. `GetinfoRequestHandler` is instantiated
2. `ConnectAndCallRPC` is called with `GetinfoRequestHandler`. It returns `UniValue::VOBJ result`
3. If `-rpcwallet` wallet is not set, `GetWalletBalances` is called with a pointer to `result` as a parameter. It adds the balances for all the wallets to `result`
4. **New** `ParseGetInfoResult` is called with `result` as parameter. It converts results type from `UniValue::VOBJ` to `UniValue::VSTR` according to the format stated above.
ACKs for top commit:
theStack:
re-ACK a37e29d
Tree-SHA512: 5e90606a397abfc4e5921f6db70a0a4888cbebba9da9b70cfe72d593caf669fd090de3e58eecf1cb5c20d5f448ad278999165d32d01667037d09bd352d23ac5d
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);
67
75
68
76
SetupChainParamsBaseOptions(argsman);
77
+
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);
69
78
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
70
79
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);
71
80
argsman.AddArg("-rpcconnect=<ip>", strprintf("Send commands to node running on <ip> (default: %s)", DEFAULT_RPCCONNECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -338,7 +347,9 @@ class GetinfoRequestHandler: public BaseRequestHandler
0 commit comments