1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use serde_json::Value;
4
5use crate::{
6 types::{
7 content_key::state::StateContentKey,
8 enr::Enr,
9 ping_extensions::extension_types::PingExtensionType,
10 portal::{
11 AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
12 PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
13 },
14 portal_wire::OfferTrace,
15 },
16 RawContentValue, RoutingTableInfo,
17};
18
19#[rpc(client, server, namespace = "portal")]
21pub trait StateNetworkApi {
22 #[method(name = "stateRoutingTableInfo")]
24 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
25
26 #[method(name = "stateRadius")]
28 async fn radius(&self) -> RpcResult<DataRadius>;
29
30 #[method(name = "stateAddEnr")]
32 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
33
34 #[method(name = "stateGetEnr")]
36 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
37
38 #[method(name = "stateDeleteEnr")]
40 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
41
42 #[method(name = "stateLookupEnr")]
44 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
45
46 #[method(name = "statePing")]
48 async fn ping(
49 &self,
50 enr: Enr,
51 payload_type: Option<PingExtensionType>,
52 payload: Option<Value>,
53 ) -> RpcResult<PongInfo>;
54
55 #[method(name = "stateFindNodes")]
58 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
59
60 #[method(name = "stateRecursiveFindNodes")]
62 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
63
64 #[method(name = "stateFindContent")]
66 async fn find_content(
67 &self,
68 enr: Enr,
69 content_key: StateContentKey,
70 ) -> RpcResult<FindContentInfo>;
71
72 #[method(name = "stateGetContent")]
75 async fn get_content(&self, content_key: StateContentKey) -> RpcResult<GetContentInfo>;
76
77 #[method(name = "stateTraceGetContent")]
80 async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;
81
82 #[method(name = "statePaginateLocalContentKeys")]
84 async fn paginate_local_content_keys(
85 &self,
86 offset: u64,
87 limit: u64,
88 ) -> RpcResult<PaginateLocalContentInfo<StateContentKey>>;
89
90 #[method(name = "statePutContent")]
93 async fn put_content(
94 &self,
95 content_key: StateContentKey,
96 content_value: RawContentValue,
97 ) -> RpcResult<PutContentInfo>;
98
99 #[method(name = "stateOffer")]
104 async fn offer(
105 &self,
106 enr: Enr,
107 content_items: Vec<(StateContentKey, RawContentValue)>,
108 ) -> RpcResult<AcceptInfo>;
109
110 #[method(name = "stateTraceOffer")]
114 async fn trace_offer(
115 &self,
116 enr: Enr,
117 content_key: StateContentKey,
118 content_value: RawContentValue,
119 ) -> RpcResult<OfferTrace>;
120
121 #[method(name = "stateStore")]
123 async fn store(
124 &self,
125 content_key: StateContentKey,
126 content_value: RawContentValue,
127 ) -> RpcResult<bool>;
128
129 #[method(name = "stateLocalContent")]
131 async fn local_content(&self, content_key: StateContentKey) -> RpcResult<RawContentValue>;
132}