Skip to content

Commit edf3167

Browse files
committed
addrinfo: raise helpfully on server error or incompatible server version
1 parent bb85cbc commit edf3167

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bitcoin-cli.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@ class AddrinfoRequestHandler : public BaseRequestHandler
256256

257257
UniValue ProcessReply(const UniValue& reply) override
258258
{
259+
if (!reply["error"].isNull()) return reply;
260+
const std::vector<UniValue>& nodes{reply["result"].getValues()};
261+
if (!nodes.empty() && nodes.at(0)["network"].isNull()) {
262+
throw std::runtime_error("-addrinfo requires bitcoind server to be running v22.0 and up");
263+
}
259264
// Count the number of peers we know by network, including torv2 versus torv3.
260265
std::array<uint64_t, m_networks_size> counts{{}};
261-
for (const UniValue& node : reply["result"].getValues()) {
266+
for (const UniValue& node : nodes) {
262267
std::string network_name{node["network"].get_str()};
263268
if (network_name == "onion") {
264269
network_name = node["address"].get_str().size() > 22 ? "torv3" : "torv2";

0 commit comments

Comments
 (0)