Skip to content

Commit 4b24544

Browse files
committed
merge bitcoin#22959: Display all proxies in -getinfo
1 parent 30b0fcf commit 4b24544

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
@@ -357,7 +357,7 @@ class GetinfoRequestHandler: public BaseRequestHandler
357357
connections.pushKV("mn_total", batch[ID_NETWORKINFO]["result"]["connections_mn"]);
358358
result.pushKV("connections", connections);
359359

360-
result.pushKV("proxy", batch[ID_NETWORKINFO]["result"]["networks"][0]["proxy"]);
360+
result.pushKV("networks", batch[ID_NETWORKINFO]["result"]["networks"]);
361361
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
362362
result.pushKV("chain", UniValue(batch[ID_BLOCKCHAININFO]["result"]["chain"]));
363363
if (!batch[ID_WALLETINFO]["result"].isNull()) {
@@ -981,8 +981,26 @@ static void ParseGetInfoResult(UniValue& result)
981981
RESET);
982982
result_string += strprintf("Version: %s\n", result["version"].getValStr());
983983
result_string += strprintf("Time offset (s): %s\n", result["timeoffset"].getValStr());
984-
const std::string proxy = result["proxy"].getValStr();
985-
result_string += strprintf("Proxy: %s\n", proxy.empty() ? "N/A" : proxy);
984+
985+
// proxies
986+
std::map<std::string, std::vector<std::string>> proxy_networks;
987+
std::vector<std::string> ordered_proxies;
988+
989+
for (const UniValue& network : result["networks"].getValues()) {
990+
const std::string proxy = network["proxy"].getValStr();
991+
if (proxy.empty()) continue;
992+
// Add proxy to ordered_proxy if has not been processed
993+
if (proxy_networks.find(proxy) == proxy_networks.end()) ordered_proxies.push_back(proxy);
994+
995+
proxy_networks[proxy].push_back(network["name"].getValStr());
996+
}
997+
998+
std::vector<std::string> formatted_proxies;
999+
for (const std::string& proxy : ordered_proxies) {
1000+
formatted_proxies.emplace_back(strprintf("%s (%s)", proxy, Join(proxy_networks.find(proxy)->second, ", ")));
1001+
}
1002+
result_string += strprintf("Proxies: %s\n", formatted_proxies.empty() ? "n/a" : Join(formatted_proxies, ", "));
1003+
9861004
result_string += strprintf("Min tx relay fee rate (%s/kB): %s\n\n", CURRENCY_UNIT, result["relayfee"].getValStr());
9871005

9881006
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()
@@ -132,10 +132,17 @@ def run_test(self):
132132
assert_equal(int(cli_get_info['Time offset (s)']), network_info['timeoffset'])
133133
expected_network_info = f"in {network_info['connections_in']}, out {network_info['connections_out']}, total {network_info['connections']}, mn_in {network_info['connections_mn_in']}, mn_out {network_info['connections_mn_out']}, mn_total {network_info['connections_mn']}"
134134
assert_equal(cli_get_info["Network"], expected_network_info)
135-
assert_equal(cli_get_info['Proxy'], network_info['networks'][0]['proxy'])
135+
assert_equal(cli_get_info['Proxies'], network_info['networks'][0]['proxy'])
136136
assert_equal(Decimal(cli_get_info['Difficulty']), blockchain_info['difficulty'])
137137
assert_equal(cli_get_info['Chain'], blockchain_info['chain'])
138138

139+
self.log.info("Test -getinfo and dash-cli return all proxies")
140+
self.restart_node(0, extra_args=["-proxy=127.0.0.1:9050", "-i2psam=127.0.0.1:7656"])
141+
network_info = self.nodes[0].getnetworkinfo()
142+
cli_get_info_string = self.nodes[0].cli('-getinfo').send_cli()
143+
cli_get_info = cli_get_info_string_to_dict(cli_get_info_string)
144+
assert_equal(cli_get_info["Proxies"], "127.0.0.1:9050 (ipv4, ipv6, onion), 127.0.0.1:7656 (i2p)")
145+
139146
if self.is_wallet_compiled():
140147
self.log.info("Test -getinfo and dash-cli getwalletinfo return expected wallet info")
141148
assert_equal(Decimal(cli_get_info['Balance']), BALANCE)

0 commit comments

Comments
 (0)