1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3
4use crate::{
5 types::{
6 content_key::state::StateContentKey,
7 enr::Enr,
8 portal::{
9 AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
10 PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
11 TracePutContentInfo,
12 },
13 portal_wire::OfferTrace,
14 },
15 RawContentValue, RoutingTableInfo,
16};
17
18#[rpc(client, server, namespace = "portal")]
20pub trait StateNetworkApi {
21 #[method(name = "stateRoutingTableInfo")]
23 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
24
25 #[method(name = "stateRadius")]
27 async fn radius(&self) -> RpcResult<DataRadius>;
28
29 #[method(name = "stateAddEnr")]
31 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
32
33 #[method(name = "stateGetEnr")]
35 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
36
37 #[method(name = "stateDeleteEnr")]
39 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
40
41 #[method(name = "stateLookupEnr")]
43 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
44
45 #[method(name = "statePing")]
47 async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;
48
49 #[method(name = "stateFindNodes")]
52 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
53
54 #[method(name = "stateRecursiveFindNodes")]
56 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
57
58 #[method(name = "stateFindContent")]
60 async fn find_content(
61 &self,
62 enr: Enr,
63 content_key: StateContentKey,
64 ) -> RpcResult<FindContentInfo>;
65
66 #[method(name = "stateGetContent")]
69 async fn get_content(&self, content_key: StateContentKey) -> RpcResult<GetContentInfo>;
70
71 #[method(name = "stateTraceGetContent")]
74 async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;
75
76 #[method(name = "statePaginateLocalContentKeys")]
78 async fn paginate_local_content_keys(
79 &self,
80 offset: u64,
81 limit: u64,
82 ) -> RpcResult<PaginateLocalContentInfo<StateContentKey>>;
83
84 #[method(name = "statePutContent")]
87 async fn put_content(
88 &self,
89 content_key: StateContentKey,
90 content_value: RawContentValue,
91 ) -> RpcResult<PutContentInfo>;
92
93 #[method(name = "stateTracePutContent")]
96 async fn trace_put_content(
97 &self,
98 content_key: StateContentKey,
99 content_value: RawContentValue,
100 ) -> RpcResult<TracePutContentInfo>;
101
102 #[method(name = "stateOffer")]
107 async fn offer(
108 &self,
109 enr: Enr,
110 content_items: Vec<(StateContentKey, RawContentValue)>,
111 ) -> RpcResult<AcceptInfo>;
112
113 #[method(name = "stateTraceOffer")]
117 async fn trace_offer(
118 &self,
119 enr: Enr,
120 content_key: StateContentKey,
121 content_value: RawContentValue,
122 ) -> RpcResult<OfferTrace>;
123
124 #[method(name = "stateStore")]
126 async fn store(
127 &self,
128 content_key: StateContentKey,
129 content_value: RawContentValue,
130 ) -> RpcResult<bool>;
131
132 #[method(name = "stateLocalContent")]
134 async fn local_content(&self, content_key: StateContentKey) -> RpcResult<RawContentValue>;
135}