| 239 | } |
| 240 | |
| 241 | UniValue getaddednodeinfo(const UniValue& params, bool fHelp) |
| 242 | { |
| 243 | if (fHelp || params.size() < 1 || params.size() > 2) |
| 244 | throw runtime_error( |
| 245 | "getaddednodeinfo dns ( \"node\" )\n" |
| 246 | "\nReturns information about the given added node, or all added nodes\n" |
| 247 | "(note that onetry addnodes are not listed here)\n" |
| 248 | "If dns is false, only a list of added nodes will be provided,\n" |
| 249 | "otherwise connected information will also be available.\n" |
| 250 | "\nArguments:\n" |
| 251 | "1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available.\n" |
| 252 | "2. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n" |
| 253 | "\nResult:\n" |
| 254 | "[\n" |
| 255 | " {\n" |
| 256 | " \"addednode\" : \"192.168.0.201\", (string) The node ip address\n" |
| 257 | " \"connected\" : true|false, (boolean) If connected\n" |
| 258 | " \"addresses\" : [\n" |
| 259 | " {\n" |
| 260 | " \"address\" : \"192.168.0.201:51472\", (string) The lux server host and port\n" |
| 261 | " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" |
| 262 | " }\n" |
| 263 | " ]\n" |
| 264 | " }\n" |
| 265 | " ,...\n" |
| 266 | "]\n" |
| 267 | "\nExamples:\n" + |
| 268 | HelpExampleCli("getaddednodeinfo", "true") + HelpExampleCli("getaddednodeinfo", "true \"192.168.0.201\"") + HelpExampleRpc("getaddednodeinfo", "true, \"192.168.0.201\"")); |
| 269 | |
| 270 | std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(); |
| 271 | |
| 272 | if (params.size() == 2) { |
| 273 | bool found = false; |
| 274 | for (const AddedNodeInfo& info : vInfo) { |
| 275 | if (info.strAddedNode == params[1].get_str()) { |
| 276 | vInfo.assign(1, info); |
| 277 | found = true; |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | if (!found) { |
| 282 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added."); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | UniValue ret(UniValue::VARR); |
| 287 | |
| 288 | for (const AddedNodeInfo& info : vInfo) { |
| 289 | UniValue obj(UniValue::VOBJ); |
| 290 | obj.push_back(Pair("addednode", info.strAddedNode)); |
| 291 | obj.push_back(Pair("connected", info.fConnected)); |
| 292 | UniValue addresses(UniValue::VARR); |
| 293 | if (info.fConnected) { |
| 294 | UniValue address(UniValue::VOBJ); |
| 295 | address.push_back(Pair("address", info.resolvedAddress.ToString())); |
| 296 | address.push_back(Pair("connected", info.fInbound ? "inbound" : "outbound")); |
| 297 | addresses.push_back(address); |
| 298 | } |
nothing calls this directly
no test coverage detected