| 270 | } |
| 271 | |
| 272 | UniValue ProcessReply(const UniValue& reply) override |
| 273 | { |
| 274 | if (!reply["error"].isNull()) return reply; |
| 275 | const std::vector<UniValue>& nodes{reply["result"].getValues()}; |
| 276 | if (!nodes.empty() && nodes.at(0)["network"].isNull()) { |
| 277 | throw std::runtime_error("-addrinfo requires bitcoind server to be running v22.0 and up"); |
| 278 | } |
| 279 | // Count the number of peers known to our node, by network. |
| 280 | std::array<uint64_t, NETWORKS.size()> counts{{}}; |
| 281 | for (const UniValue& node : nodes) { |
| 282 | std::string network_name{node["network"].get_str()}; |
| 283 | const int8_t network_id{NetworkStringToId(network_name)}; |
| 284 | if (network_id == UNKNOWN_NETWORK) continue; |
| 285 | ++counts.at(network_id); |
| 286 | } |
| 287 | // Prepare result to return to user. |
| 288 | UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ}; |
| 289 | uint64_t total{0}; // Total address count |
| 290 | for (size_t i = 0; i < NETWORKS.size(); ++i) { |
| 291 | addresses.pushKV(NETWORKS[i], counts.at(i)); |
| 292 | total += counts.at(i); |
| 293 | } |
| 294 | addresses.pushKV("total", total); |
| 295 | result.pushKV("addresses_known", addresses); |
| 296 | return JSONRPCReplyObj(result, NullUniValue, 1); |
| 297 | } |
| 298 | }; |
| 299 | |
| 300 | /** Process getinfo requests */ |
nothing calls this directly
no test coverage detected