1use alloy_rpc_types_admin::{NodeInfo, PeerInfo};
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use reth_network_peers::{AnyNode, NodeRecord};
45/// 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")]
11fn add_peer(&self, record: NodeRecord) -> RpcResult<bool>;
1213/// Disconnects from a remote node if the connection exists.
14 ///
15 /// Returns true if the peer was successfully removed.
16#[method(name = "removePeer")]
17fn remove_peer(&self, record: AnyNode) -> RpcResult<bool>;
1819/// Adds the given node record to the trusted peerset.
20#[method(name = "addTrustedPeer")]
21fn add_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
2223/// 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")]
28fn remove_trusted_peer(&self, record: AnyNode) -> RpcResult<bool>;
2930/// 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")]
35async fn peers(&self) -> RpcResult<Vec<PeerInfo>>;
3637/// Creates an RPC subscription which serves events received from the network.
38#[subscription(
39 name = "peerEvents",
40 unsubscribe = "peerEvents_unsubscribe",
41 item = String
42 )]
43async fn subscribe_peer_events(&self) -> jsonrpsee::core::SubscriptionResult;
4445/// Returns the ENR of the node.
46#[method(name = "nodeInfo")]
47async fn node_info(&self) -> RpcResult<NodeInfo>;
48}