ethportal_api/
discv5.rs

1use alloy::primitives::bytes::Bytes;
2use discv5::enr::NodeId;
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5use crate::types::{
6    discv5::{NodeInfo, Pong, RoutingTableInfo},
7    enr::Enr,
8    network::Subnetwork,
9};
10
11/// Discv5 JSON-RPC endpoints
12#[rpc(client, server, namespace = "discv5")]
13pub trait Discv5Api {
14    /// Returns ENR and Node ID information of the local discv5 node.
15    #[method(name = "nodeInfo")]
16    async fn node_info(&self) -> RpcResult<NodeInfo>;
17
18    /// Update the socket address of the local node record.
19    #[method(name = "updateNodeInfo")]
20    async fn update_node_info(&self, socket_addr: String, is_tcp: bool) -> RpcResult<NodeInfo>;
21
22    /// Returns meta information about discv5 routing table.
23    #[method(name = "routingTableInfo")]
24    async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
25
26    /// Write an Ethereum Node Record to the routing table.
27    #[method(name = "addEnr")]
28    async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
29
30    /// Fetch the latest ENR associated with the given node ID.
31    #[method(name = "getEnr")]
32    async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
33
34    /// Delete Node ID from the routing table.
35    #[method(name = "deleteEnr")]
36    async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
37
38    /// Fetch the ENR representation associated with the given Node ID.
39    #[method(name = "lookupEnr")]
40    async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
41
42    /// Look up ENRs closest to the given target
43    #[method(name = "recursiveFindNodes")]
44    async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
45
46    /// Send a TALKREQ request with a payload to a given peer and wait for response.
47    #[method(name = "talkReq")]
48    async fn talk_req(&self, enr: Enr, protocol: Subnetwork, request: Vec<u8>) -> RpcResult<Bytes>;
49
50    /// Send a PING message to the designated node and wait for a PONG response.
51    #[method(name = "ping")]
52    async fn ping(&self, enr: Enr) -> RpcResult<Pong>;
53
54    /// Send a FINDNODE request for nodes that fall within the given set of distances, to the
55    /// designated peer and wait for a response.
56    #[method(name = "findNode")]
57    async fn find_node(&self, enr: Enr, distances: Vec<u64>) -> RpcResult<Vec<Enr>>;
58}