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 },
14 portal_wire::OfferTrace,
15 },
16 RawContentValue, RoutingTableInfo,
17};
18
19#[rpc(client, server, namespace = "portal")]
21pub trait HistoryNetworkApi {
22 #[method(name = "historyRoutingTableInfo")]
24 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
25
26 #[method(name = "historyRadius")]
28 async fn radius(&self) -> RpcResult<DataRadius>;
29
30 #[method(name = "historyAddEnr")]
32 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
33
34 #[method(name = "historyGetEnr")]
36 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
37
38 #[method(name = "historyDeleteEnr")]
40 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
41
42 #[method(name = "historyLookupEnr")]
44 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
45
46 #[method(name = "historyPing")]
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 = "historyFindNodes")]
58 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
59
60 #[method(name = "historyRecursiveFindNodes")]
62 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
63
64 #[method(name = "historyFindContent")]
66 async fn find_content(
67 &self,
68 enr: Enr,
69 content_key: HistoryContentKey,
70 ) -> RpcResult<FindContentInfo>;
71
72 #[method(name = "historyGetContent")]
75 async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<GetContentInfo>;
76
77 #[method(name = "historyTraceGetContent")]
80 async fn trace_get_content(
81 &self,
82 content_key: HistoryContentKey,
83 ) -> RpcResult<TraceContentInfo>;
84
85 #[method(name = "historyPaginateLocalContentKeys")]
87 async fn paginate_local_content_keys(
88 &self,
89 offset: u64,
90 limit: u64,
91 ) -> RpcResult<PaginateLocalContentInfo<HistoryContentKey>>;
92
93 #[method(name = "historyPutContent")]
96 async fn put_content(
97 &self,
98 content_key: HistoryContentKey,
99 content_value: RawContentValue,
100 ) -> RpcResult<PutContentInfo>;
101
102 #[method(name = "historyOffer")]
107 async fn offer(
108 &self,
109 enr: Enr,
110 content_items: Vec<(HistoryContentKey, RawContentValue)>,
111 ) -> RpcResult<AcceptInfo>;
112
113 #[method(name = "historyTraceOffer")]
117 async fn trace_offer(
118 &self,
119 enr: Enr,
120 content_key: HistoryContentKey,
121 content_value: RawContentValue,
122 ) -> RpcResult<OfferTrace>;
123
124 #[method(name = "historyStore")]
126 async fn store(
127 &self,
128 content_key: HistoryContentKey,
129 content_value: RawContentValue,
130 ) -> RpcResult<bool>;
131
132 #[method(name = "historyLocalContent")]
134 async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
135}