reth_rpc_api/
admin.rs

1use alloy_rpc_types_admin::{NodeInfo, PeerInfo};
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use reth_network_peers::{AnyNode, NodeRecord};
4
5/// Admin namespace rpc interface that gives access to several non-standard RPC methods.
6#[cfg_attr(not(feature = "client"), rpc(server, namespace = "admin"))]
7#[cfg_attr(feature = "client", rpc(server, client, namespace = "admin"))]
8pub trait AdminApi {
9    /// Adds the given node record to the peerset.
10    #[method(name = "addPeer")]
11    fn add_peer(&self, record: NodeRecord) -> RpcResult<bool>;
12
13    /// Disconnects from a remote node if the connection exists.
14    ///
15    /// Returns true if the peer was successfully removed.
16    #[method(name = "removePeer")]
17    fn remove_peer(&self, record: AnyNode) -> RpcResult<bool>;
18
19    /// Adds the given node record to the trusted peerset.
20    #[method(name = "addTrustedPeer")]
21    fn add_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
22
23    /// Removes a remote node from the trusted peer set, but it does not disconnect it
24    /// automatically.
25    ///
26    /// Returns true if the peer was successfully removed.
27    #[method(name = "removeTrustedPeer")]
28    fn remove_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
29
30    /// The peers administrative property can be queried for all the information known about the
31    /// connected remote nodes at the networking granularity. These include general information
32    /// about the nodes themselves as participants of the devp2p P2P overlay protocol, as well as
33    /// specialized information added by each of the running application protocols
34    #[method(name = "peers")]
35    async fn peers(&self) -> RpcResult<Vec<PeerInfo>>;
36
37    /// Creates an RPC subscription which serves events received from the network.
38    #[subscription(
39        name = "peerEvents",
40        unsubscribe = "peerEvents_unsubscribe",
41        item = String
42    )]
43    async fn subscribe_peer_events(&self) -> jsonrpsee::core::SubscriptionResult;
44
45    /// Returns the ENR of the node.
46    #[method(name = "nodeInfo")]
47    async fn node_info(&self) -> RpcResult<NodeInfo>;
48}