diff options
author | Jon Atack <jon@atack.com> | 2020-10-25 15:07:01 +0100 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-10-25 16:51:18 +0100 |
commit | 773f4c99c00c0b1d8c1b53cb99ba571337100953 (patch) | |
tree | 1e9a06dfdd00632804bac4cb910372ab20fd6d02 /src | |
parent | 33e987452f869c279f2491499939e51e0af8364c (diff) |
cli -netinfo: handle longer tor v3 local addresses
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-cli.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 59e7ef312b..8e17319425 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -20,6 +20,7 @@ #include <util/translation.h> #include <util/url.h> +#include <algorithm> #include <functional> #include <memory> #include <stdio.h> @@ -455,12 +456,16 @@ public: // Report local addresses, ports, and scores. result += "\nLocal addresses"; - const UniValue& local_addrs{networkinfo["localaddresses"]}; + const std::vector<UniValue>& local_addrs{networkinfo["localaddresses"].getValues()}; if (local_addrs.empty()) { result += ": n/a\n"; } else { - for (const UniValue& addr : local_addrs.getValues()) { - result += strprintf("\n%-40i port %5i score %6i", addr["address"].get_str(), addr["port"].get_int(), addr["score"].get_int()); + size_t max_addr_size{0}; + for (const UniValue& addr : local_addrs) { + max_addr_size = std::max(addr["address"].get_str().length() + 1, max_addr_size); + } + for (const UniValue& addr : local_addrs) { + result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].get_int(), addr["score"].get_int()); } } |