1use alloy::primitives::B256;
2use discv5::enr::NodeId;
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5use crate::{
6 consensus::header::BeaconBlockHeader,
7 light_client::store::LightClientStore,
8 types::{
9 consensus::light_client::{
10 finality_update::LightClientFinalityUpdate,
11 optimistic_update::LightClientOptimisticUpdate,
12 },
13 content_key::beacon::BeaconContentKey,
14 enr::Enr,
15 portal::{
16 AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
17 PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
18 TracePutContentInfo,
19 },
20 portal_wire::OfferTrace,
21 },
22 RawContentValue, RoutingTableInfo,
23};
24
25#[rpc(client, server, namespace = "portal")]
27pub trait BeaconNetworkApi {
28 #[method(name = "beaconRoutingTableInfo")]
30 async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
31
32 #[method(name = "beaconRadius")]
34 async fn radius(&self) -> RpcResult<DataRadius>;
35
36 #[method(name = "beaconAddEnr")]
38 async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
39
40 #[method(name = "beaconGetEnr")]
42 async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
43
44 #[method(name = "beaconDeleteEnr")]
46 async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
47
48 #[method(name = "beaconLightClientStore")]
50 async fn light_client_store(&self) -> RpcResult<LightClientStore>;
51
52 #[method(name = "beaconLookupEnr")]
54 async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
55
56 #[method(name = "beaconPing")]
58 async fn ping(&self, enr: Enr) -> RpcResult<PongInfo>;
59
60 #[method(name = "beaconFinalizedStateRoot")]
62 async fn finalized_state_root(&self) -> RpcResult<B256>;
63
64 #[method(name = "beaconFinalizedHeader")]
66 async fn finalized_header(&self) -> RpcResult<BeaconBlockHeader>;
67
68 #[method(name = "beaconFinalityUpdate")]
70 async fn finality_update(&self) -> RpcResult<LightClientFinalityUpdate>;
71
72 #[method(name = "beaconOptimisticUpdate")]
74 async fn optimistic_update(&self) -> RpcResult<LightClientOptimisticUpdate>;
75
76 #[method(name = "beaconFindNodes")]
79 async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
80
81 #[method(name = "beaconRecursiveFindNodes")]
83 async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
84
85 #[method(name = "beaconOptimisticStateRoot")]
87 async fn optimistic_state_root(&self) -> RpcResult<B256>;
88
89 #[method(name = "beaconFindContent")]
91 async fn find_content(
92 &self,
93 enr: Enr,
94 content_key: BeaconContentKey,
95 ) -> RpcResult<FindContentInfo>;
96
97 #[method(name = "beaconGetContent")]
100 async fn get_content(&self, content_key: BeaconContentKey) -> RpcResult<GetContentInfo>;
101
102 #[method(name = "beaconTraceGetContent")]
105 async fn trace_get_content(&self, content_key: BeaconContentKey)
106 -> RpcResult<TraceContentInfo>;
107
108 #[method(name = "beaconPaginateLocalContentKeys")]
110 async fn paginate_local_content_keys(
111 &self,
112 offset: u64,
113 limit: u64,
114 ) -> RpcResult<PaginateLocalContentInfo<BeaconContentKey>>;
115
116 #[method(name = "beaconPutContent")]
119 async fn put_content(
120 &self,
121 content_key: BeaconContentKey,
122 content_value: RawContentValue,
123 ) -> RpcResult<PutContentInfo>;
124
125 #[method(name = "beaconTracePutContent")]
128 async fn trace_put_content(
129 &self,
130 content_key: BeaconContentKey,
131 content_value: RawContentValue,
132 ) -> RpcResult<TracePutContentInfo>;
133
134 #[method(name = "beaconOffer")]
139 async fn offer(
140 &self,
141 enr: Enr,
142 content_items: Vec<(BeaconContentKey, RawContentValue)>,
143 ) -> RpcResult<AcceptInfo>;
144
145 #[method(name = "beaconTraceOffer")]
149 async fn trace_offer(
150 &self,
151 enr: Enr,
152 content_key: BeaconContentKey,
153 content_value: RawContentValue,
154 ) -> RpcResult<OfferTrace>;
155
156 #[method(name = "beaconStore")]
158 async fn store(
159 &self,
160 content_key: BeaconContentKey,
161 content_value: RawContentValue,
162 ) -> RpcResult<bool>;
163
164 #[method(name = "beaconLocalContent")]
166 async fn local_content(&self, content_key: BeaconContentKey) -> RpcResult<RawContentValue>;
167}