| 496 | } |
| 497 | |
| 498 | static RPCMethod getaddednodeinfo() |
| 499 | { |
| 500 | return RPCMethod{ |
| 501 | "getaddednodeinfo", |
| 502 | "Returns information about the given added node, or all added nodes\n" |
| 503 | "(note that onetry addnodes are not listed here)\n", |
| 504 | { |
| 505 | {"node", RPCArg::Type::STR, RPCArg::DefaultHint{"all nodes"}, "If provided, return information about this specific node, otherwise all nodes are returned."}, |
| 506 | }, |
| 507 | RPCResult{ |
| 508 | RPCResult::Type::ARR, "", "", |
| 509 | { |
| 510 | {RPCResult::Type::OBJ, "", "", |
| 511 | { |
| 512 | {RPCResult::Type::STR, "addednode", "The node IP address or name (as provided to addnode)"}, |
| 513 | {RPCResult::Type::BOOL, "connected", "If connected"}, |
| 514 | {RPCResult::Type::ARR, "addresses", "Only when connected = true", |
| 515 | { |
| 516 | {RPCResult::Type::OBJ, "", "", |
| 517 | { |
| 518 | {RPCResult::Type::STR, "address", "The bitcoin server IP and port we're connected to"}, |
| 519 | {RPCResult::Type::STR, "connected", "connection, inbound or outbound"}, |
| 520 | }}, |
| 521 | }}, |
| 522 | }}, |
| 523 | } |
| 524 | }, |
| 525 | RPCExamples{ |
| 526 | HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") |
| 527 | + HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"") |
| 528 | }, |
| 529 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 530 | { |
| 531 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 532 | const CConnman& connman = EnsureConnman(node); |
| 533 | |
| 534 | std::vector<AddedNodeInfo> vInfo = connman.GetAddedNodeInfo(/*include_connected=*/true); |
| 535 | |
| 536 | if (auto node{self.MaybeArg<std::string_view>("node")}) { |
| 537 | bool found = false; |
| 538 | for (const AddedNodeInfo& info : vInfo) { |
| 539 | if (info.m_params.m_added_node == *node) { |
| 540 | vInfo.assign(1, info); |
| 541 | found = true; |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | if (!found) { |
| 546 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added."); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | UniValue ret(UniValue::VARR); |
| 551 | |
| 552 | for (const AddedNodeInfo& info : vInfo) { |
| 553 | UniValue obj(UniValue::VOBJ); |
| 554 | obj.pushKV("addednode", info.m_params.m_added_node); |
| 555 | obj.pushKV("connected", info.fConnected); |
nothing calls this directly
no test coverage detected