1use discv5::enr::NodeId;
2use jsonrpsee::{core::RpcResult, proc_macros::rpc};
3use serde_json::Value;
4
5use crate::{
6 types::{
7 enr::Enr,
8 ping_extensions::extension_types::PingExtensionType,
9 portal::{
10 AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo, PongInfo,
11 PutContentInfo, TraceContentInfo,
12 },
13 portal_wire::OfferTrace,
14 },
15 HistoryContentKey, RawContentValue, RoutingTableInfo,
16};
17
18#[rpc(client, server, namespace = "portal")]
20pub trait HistoryNetworkApi {
21 #[method(name = "historyRoutingTableInfo")]
23 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
24
25 #[method(name = "historyRadius")]
27 async fn radius(&self) -> RpcResult<DataRadius>;
28
29 #[method(name = "historyAddEnr")]
31 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
32
33 #[method(name = "historyGetEnr")]
35 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
36
37 #[method(name = "historyDeleteEnr")]
39 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
40
41 #[method(name = "historyLookupEnr")]
43 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
44
45 #[method(name = "historyPing")]
47 async fn ping(
48 &self,
49 enr: Enr,
50 payload_type: Option<PingExtensionType>,
51 payload: Option<Value>,
52 ) -> RpcResult<PongInfo>;
53
54 #[method(name = "historyFindNodes")]
57 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
58
59 #[method(name = "historyRecursiveFindNodes")]
61 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
62
63 #[method(name = "historyFindContent")]
65 async fn find_content(
66 &self,
67 enr: Enr,
68 content_key: HistoryContentKey,
69 ) -> RpcResult<FindContentInfo>;
70
71 #[method(name = "historyGetContent")]
74 async fn get_content(&self, content_key: HistoryContentKey) -> RpcResult<GetContentInfo>;
75
76 #[method(name = "historyTraceGetContent")]
79 async fn trace_get_content(
80 &self,
81 content_key: HistoryContentKey,
82 ) -> RpcResult<TraceContentInfo>;
83
84 #[method(name = "historyPutContent")]
87 async fn put_content(
88 &self,
89 content_key: HistoryContentKey,
90 content_value: RawContentValue,
91 ) -> RpcResult<PutContentInfo>;
92
93 #[method(name = "historyOffer")]
98 async fn offer(
99 &self,
100 enr: Enr,
101 content_items: Vec<(HistoryContentKey, RawContentValue)>,
102 ) -> RpcResult<AcceptInfo>;
103
104 #[method(name = "historyTraceOffer")]
108 async fn trace_offer(
109 &self,
110 enr: Enr,
111 content_key: HistoryContentKey,
112 content_value: RawContentValue,
113 ) -> RpcResult<OfferTrace>;
114
115 #[method(name = "historyStore")]
117 async fn store(
118 &self,
119 content_key: HistoryContentKey,
120 content_value: RawContentValue,
121 ) -> RpcResult<bool>;
122
123 #[method(name = "historyLocalContent")]
125 async fn local_content(&self, content_key: HistoryContentKey) -> RpcResult<RawContentValue>;
126}