| 428 | } |
| 429 | |
| 430 | static RPCHelpMan getaddednodeinfo() |
| 431 | { |
| 432 | return RPCHelpMan{"getaddednodeinfo", |
| 433 | "\nReturns information about the given added node, or all added nodes\n" |
| 434 | "(note that onetry addnodes are not listed here)\n", |
| 435 | { |
| 436 | {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"}, "If provided, return information about this specific node, otherwise all nodes are returned."}, |
| 437 | }, |
| 438 | RPCResult{ |
| 439 | RPCResult::Type::ARR, "", "", |
| 440 | { |
| 441 | {RPCResult::Type::OBJ, "", "", |
| 442 | { |
| 443 | {RPCResult::Type::STR, "addednode", "The node IP address or name (as provided to addnode)"}, |
| 444 | {RPCResult::Type::BOOL, "connected", "If connected"}, |
| 445 | {RPCResult::Type::ARR, "addresses", "Only when connected = true", |
| 446 | { |
| 447 | {RPCResult::Type::OBJ, "", "", |
| 448 | { |
| 449 | {RPCResult::Type::STR, "address", "The bitcoin server IP and port we're connected to"}, |
| 450 | {RPCResult::Type::STR, "connected", "connection, inbound or outbound"}, |
| 451 | }}, |
| 452 | }}, |
| 453 | }}, |
| 454 | } |
| 455 | }, |
| 456 | RPCExamples{ |
| 457 | HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") |
| 458 | + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"") |
| 459 | }, |
| 460 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 461 | { |
| 462 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 463 | const CConnman& connman = EnsureConnman(node); |
| 464 | |
| 465 | std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo(); |
| 466 | |
| 467 | if (!request.params[0].isNull()) { |
| 468 | bool found = false; |
| 469 | for (const AddedNodeInfo& info : vInfo) { |
| 470 | if (info.strAddedNode == request.params[0].get_str()) { |
| 471 | vInfo.assign(1, info); |
| 472 | found = true; |
| 473 | break; |
| 474 | } |
| 475 | } |
| 476 | if (!found) { |
| 477 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added."); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | UniValue ret(UniValue::VARR); |
| 482 | |
| 483 | for (const AddedNodeInfo& info : vInfo) { |
| 484 | UniValue obj(UniValue::VOBJ); |
| 485 | obj.pushKV("addednode", info.strAddedNode); |
| 486 | obj.pushKV("connected", info.fConnected); |
| 487 | UniValue addresses(UniValue::VARR); |
nothing calls this directly
no test coverage detected