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 TracePutContentInfo,
14 },
15 portal_wire::OfferTrace,
16 },
17 RawContentValue, RoutingTableInfo,
18};
19
20#[rpc(client, server, namespace = "portal")]
22pub trait StateNetworkApi {
23 #[method(name = "stateRoutingTableInfo")]
25 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
26
27 #[method(name = "stateRadius")]
29 async fn radius(&self) -> RpcResult<DataRadius>;
30
31 #[method(name = "stateAddEnr")]
33 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
34
35 #[method(name = "stateGetEnr")]
37 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
38
39 #[method(name = "stateDeleteEnr")]
41 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
42
43 #[method(name = "stateLookupEnr")]
45 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
46
47 #[method(name = "statePing")]
49 async fn ping(
50 &self,
51 enr: Enr,
52 payload_type: Option<PingExtensionType>,
53 payload: Option<Value>,
54 ) -> RpcResult<PongInfo>;
55
56 #[method(name = "stateFindNodes")]
59 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
60
61 #[method(name = "stateRecursiveFindNodes")]
63 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
64
65 #[method(name = "stateFindContent")]
67 async fn find_content(
68 &self,
69 enr: Enr,
70 content_key: StateContentKey,
71 ) -> RpcResult<FindContentInfo>;
72
73 #[method(name = "stateGetContent")]
76 async fn get_content(&self, content_key: StateContentKey) -> RpcResult<GetContentInfo>;
77
78 #[method(name = "stateTraceGetContent")]
81 async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;
82
83 #[method(name = "statePaginateLocalContentKeys")]
85 async fn paginate_local_content_keys(
86 &self,
87 offset: u64,
88 limit: u64,
89 ) -> RpcResult<PaginateLocalContentInfo<StateContentKey>>;
90
91 #[method(name = "statePutContent")]
94 async fn put_content(
95 &self,
96 content_key: StateContentKey,
97 content_value: RawContentValue,
98 ) -> RpcResult<PutContentInfo>;
99
100 #[method(name = "stateTracePutContent")]
103 async fn trace_put_content(
104 &self,
105 content_key: StateContentKey,
106 content_value: RawContentValue,
107 ) -> RpcResult<TracePutContentInfo>;
108
109 #[method(name = "stateOffer")]
114 async fn offer(
115 &self,
116 enr: Enr,
117 content_items: Vec<(StateContentKey, RawContentValue)>,
118 ) -> RpcResult<AcceptInfo>;
119
120 #[method(name = "stateTraceOffer")]
124 async fn trace_offer(
125 &self,
126 enr: Enr,
127 content_key: StateContentKey,
128 content_value: RawContentValue,
129 ) -> RpcResult<OfferTrace>;
130
131 #[method(name = "stateStore")]
133 async fn store(
134 &self,
135 content_key: StateContentKey,
136 content_value: RawContentValue,
137 ) -> RpcResult<bool>;
138
139 #[method(name = "stateLocalContent")]
141 async fn local_content(&self, content_key: StateContentKey) -> RpcResult<RawContentValue>;
142}