Skip to content

Commit d809d8b

Browse files
committed
Merge bitcoin/bitcoin#22959: cli: Display all proxies in -getinfo
7c3712f cli: Display all proxies in -getinfo (klementtan) Pull request description: **Changes**: Display all proxies in `-getinfo` **Motivation**: * Currently `-getinfo` only return the proxy of the first network in `getnetworkinfo`. * This PR will display all unique proxies in `getnetworkinfo` as suggested in bitcoin/bitcoin#17314 (comment) >List all proxies, at least if they're different from the IPv4 one ![image](https://user-images.githubusercontent.com/49265907/133991832-a1f38b36-2975-4ce2-a427-e4ffab23383e.png) **Testing**: You can verify this change by starting bitcoind with ```shell ./src/bitcoind -signet --proxy=127.0.0.1:9050 --i2psam=127.0.0.1:7656 ``` Execute `-getinfo` ```shell ./src/bitcoin-cli -signet -getinfo ``` ACKs for top commit: laanwj: Tested ACK 7c3712f prayank23: utACK bitcoin/bitcoin@7c3712f Tree-SHA512: 9eae97866220227f30ca4585f52799fa66fc1135047d869c4aabe598aee1a9414cb9e1c4a8d19165e52d65005f3c6d4bcc37463ace0ddb44389dfbcd4ca74095
2 parents 226731a + 7c3712f commit d809d8b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/bitcoin-cli.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
337337
connections.pushKV("total", batch[ID_NETWORKINFO]["result"]["connections"]);
338338
result.pushKV("connections", connections);
339339

340-
result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
340+
result.pushKV("networks", batch[ID_NETWORKINFO]["result"]["networks"]);
341341
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
342342
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));
343343
if (!batch[ID_WALLETINFO]["result"].isNull()) {
@@ -986,8 +986,26 @@ static void ParseGetInfoResult(UniValue& result)
986986
RESET);
987987
result_string += strprintf("Version: %s\n", result["version"].getValStr());
988988
result_string += strprintf("Time offset (s): %s\n", result["timeoffset"].getValStr());
989-
const std::string proxy = result["proxy"].getValStr();
990-
result_string += strprintf("Proxy: %s\n", proxy.empty() ? "N/A" : proxy);
989+
990+
// proxies
991+
std::map<std::string, std::vector<std::string>> proxy_networks;
992+
std::vector<std::string> ordered_proxies;
993+
994+
for (const UniValue& network : result["networks"].getValues()) {
995+
const std::string proxy = network["proxy"].getValStr();
996+
if (proxy.empty()) continue;
997+
// Add proxy to ordered_proxy if has not been processed
998+
if (proxy_networks.find(proxy) == proxy_networks.end()) ordered_proxies.push_back(proxy);
999+
1000+
proxy_networks[proxy].push_back(network["name"].getValStr());
1001+
}
1002+
1003+
std::vector<std::string> formatted_proxies;
1004+
for (const std::string& proxy : ordered_proxies) {
1005+
formatted_proxies.emplace_back(strprintf("%s (%s)", proxy, Join(proxy_networks.find(proxy)->second, ", ")));
1006+
}
1007+
result_string += strprintf("Proxies: %s\n", formatted_proxies.empty() ? "n/a" : Join(formatted_proxies, ", "));
1008+
9911009
result_string += strprintf("Min tx relay fee rate (%s/kvB): %s\n\n", CURRENCY_UNIT, result["relayfee"].getValStr());
9921010

9931011
if (!result["has_wallet"].isNull()) {

test/functional/interface_bitcoin_cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def cli_get_info_string_to_dict(cli_get_info_string):
5757
if key == 'Wallet' and value == '""':
5858
# Set default wallet("") to empty string
5959
value = ''
60-
if key == "Proxy" and value == "N/A":
60+
if key == "Proxies" and value == "n/a":
6161
# Set N/A to empty string to represent no proxy
6262
value = ''
6363
cli_get_info[key.strip()] = value.strip()
@@ -127,10 +127,17 @@ def run_test(self):
127127
assert_equal(int(cli_get_info['Time offset (s)']), network_info['timeoffset'])
128128
expected_network_info = f"in {network_info['connections_in']}, out {network_info['connections_out']}, total {network_info['connections']}"
129129
assert_equal(cli_get_info["Network"], expected_network_info)
130-
assert_equal(cli_get_info['Proxy'], network_info['networks'][0]['proxy'])
130+
assert_equal(cli_get_info['Proxies'], network_info['networks'][0]['proxy'])
131131
assert_equal(Decimal(cli_get_info['Difficulty']), blockchain_info['difficulty'])
132132
assert_equal(cli_get_info['Chain'], blockchain_info['chain'])
133133

134+
self.log.info("Test -getinfo and bitcoin-cli return all proxies")
135+
self.restart_node(0, extra_args=["-proxy=127.0.0.1:9050", "-i2psam=127.0.0.1:7656"])
136+
network_info = self.nodes[0].getnetworkinfo()
137+
cli_get_info_string = self.nodes[0].cli('-getinfo').send_cli()
138+
cli_get_info = cli_get_info_string_to_dict(cli_get_info_string)
139+
assert_equal(cli_get_info["Proxies"], "127.0.0.1:9050 (ipv4, ipv6, onion), 127.0.0.1:7656 (i2p)")
140+
134141
if self.is_wallet_compiled():
135142
self.log.info("Test -getinfo and bitcoin-cli getwalletinfo return expected wallet info")
136143
assert_equal(Decimal(cli_get_info['Balance']), BALANCE)

0 commit comments

Comments
 (0)