| 281 | } |
| 282 | |
| 283 | static UniValue getaddednodeinfo(const JSONRPCRequest& request) |
| 284 | { |
| 285 | if (request.fHelp || request.params.size() > 1) |
| 286 | throw std::runtime_error( |
| 287 | "getaddednodeinfo ( \"node\" )\n" |
| 288 | "\nReturns information about the given added node, or all added nodes\n" |
| 289 | "(note that onetry addnodes are not listed here)\n" |
| 290 | "\nArguments:\n" |
| 291 | "1. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n" |
| 292 | "\nResult:\n" |
| 293 | "[\n" |
| 294 | " {\n" |
| 295 | " \"addednode\" : \"192.168.0.201\", (string) The node IP address or name (as provided to addnode)\n" |
| 296 | " \"connected\" : true|false, (boolean) If connected\n" |
| 297 | " \"addresses\" : [ (list of objects) Only when connected = true\n" |
| 298 | " {\n" |
| 299 | " \"address\" : \"192.168.0.201:8338\", (string) The bitcoin server IP and port we're connected to\n" |
| 300 | " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" |
| 301 | " }\n" |
| 302 | " ]\n" |
| 303 | " }\n" |
| 304 | " ,...\n" |
| 305 | "]\n" |
| 306 | "\nExamples:\n" |
| 307 | + HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") |
| 308 | + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"") |
| 309 | ); |
| 310 | |
| 311 | if(!g_connman) |
| 312 | throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); |
| 313 | |
| 314 | std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo(); |
| 315 | |
| 316 | if (!request.params[0].isNull()) { |
| 317 | bool found = false; |
| 318 | for (const AddedNodeInfo& info : vInfo) { |
| 319 | if (info.strAddedNode == request.params[0].get_str()) { |
| 320 | vInfo.assign(1, info); |
| 321 | found = true; |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | if (!found) { |
| 326 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added."); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | UniValue ret(UniValue::VARR); |
| 331 | |
| 332 | for (const AddedNodeInfo& info : vInfo) { |
| 333 | UniValue obj(UniValue::VOBJ); |
| 334 | obj.pushKV("addednode", info.strAddedNode); |
| 335 | obj.pushKV("connected", info.fConnected); |
| 336 | UniValue addresses(UniValue::VARR); |
| 337 | if (info.fConnected) { |
| 338 | UniValue address(UniValue::VOBJ); |
| 339 | address.pushKV("address", info.resolvedAddress.ToString()); |
| 340 | address.pushKV("connected", info.fInbound ? "inbound" : "outbound"); |
nothing calls this directly
no test coverage detected