aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoin-cli.cpp
diff options
context:
space:
mode:
authorJon Atack <jon@atack.com>2021-04-09 09:40:57 +0200
committerJon Atack <jon@atack.com>2021-04-12 22:12:41 +0200
commitedf3167151f7a6d08cf733b4e230e2d745819ac8 (patch)
treefa3458d87400c7d471c975e7d53ea5454d33af7e /src/bitcoin-cli.cpp
parentbb85cbc4f7638a85049658ed951a0e06e7959cd4 (diff)
downloadbitcoin-edf3167151f7a6d08cf733b4e230e2d745819ac8.tar.xz
addrinfo: raise helpfully on server error or incompatible server version
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r--src/bitcoin-cli.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 2f7e49eccb..2b541be83e 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -256,9 +256,14 @@ public:
UniValue ProcessReply(const UniValue& reply) override
{
+ if (!reply["error"].isNull()) return reply;
+ const std::vector<UniValue>& nodes{reply["result"].getValues()};
+ if (!nodes.empty() && nodes.at(0)["network"].isNull()) {
+ throw std::runtime_error("-addrinfo requires bitcoind server to be running v22.0 and up");
+ }
// Count the number of peers we know by network, including torv2 versus torv3.
std::array<uint64_t, m_networks_size> counts{{}};
- for (const UniValue& node : reply["result"].getValues()) {
+ for (const UniValue& node : nodes) {
std::string network_name{node["network"].get_str()};
if (network_name == "onion") {
network_name = node["address"].get_str().size() > 22 ? "torv3" : "torv2";