1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use serde_json::Value;
4
5use crate::{
6 types::{
7 content_key::history::HistoryContentKey,
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 HistoryNetworkApi {
23 #[method(name = "historyRoutingTableInfo")]
25 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
26
27 #[method(name = "historyRadius")]
29 async fn radius(&self) -> RpcResult<DataRadius>;
30
31 #[method(name = "historyAddEnr")]
33 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
34
35 #[method(name = "historyGetEnr")]
37 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
38
39 #[method(name = "historyDeleteEnr")]
41 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
42
43 #[method(name = "historyLookupEnr")]
45 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
46
47 #[method(name = "historyPing")]
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 = "historyFindNodes")]
59 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
60
61 #[method(name = "historyRecursiveFindNodes")]
63 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
64
65 #[method(name = "historyFindContent")]
67 async fn find_content(
68 &self,
69 enr: Enr,
70 content_key: HistoryContentKey,
71 ) -> RpcResult<FindContentInfo>;
72
73 #[method(name = "historyGetContent")]
76 async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<GetContentInfo>;
77
78 #[method(name = "historyTraceGetContent")]
81 async fn trace_get_content(
82 &self,
83 content_key: HistoryContentKey,
84 ) -> RpcResult<TraceContentInfo>;
85
86 #[method(name = "historyPaginateLocalContentKeys")]
88 async fn paginate_local_content_keys(
89 &self,
90 offset: u64,
91 limit: u64,
92 ) -> RpcResult<PaginateLocalContentInfo<HistoryContentKey>>;
93
94 #[method(name = "historyPutContent")]
97 async fn put_content(
98 &self,
99 content_key: HistoryContentKey,
100 content_value: RawContentValue,
101 ) -> RpcResult<PutContentInfo>;
102
103 #[method(name = "historyTracePutContent")]
106 async fn trace_put_content(
107 &self,
108 content_key: HistoryContentKey,
109 content_value: RawContentValue,
110 ) -> RpcResult<TracePutContentInfo>;
111
112 #[method(name = "historyOffer")]
117 async fn offer(
118 &self,
119 enr: Enr,
120 content_items: Vec<(HistoryContentKey, RawContentValue)>,
121 ) -> RpcResult<AcceptInfo>;
122
123 #[method(name = "historyTraceOffer")]
127 async fn trace_offer(
128 &self,
129 enr: Enr,
130 content_key: HistoryContentKey,
131 content_value: RawContentValue,
132 ) -> RpcResult<OfferTrace>;
133
134 #[method(name = "historyStore")]
136 async fn store(
137 &self,
138 content_key: HistoryContentKey,
139 content_value: RawContentValue,
140 ) -> RpcResult<bool>;
141
142 #[method(name = "historyLocalContent")]
144 async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
145}