use discv5::enr::NodeId;
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use serde_json::Value;
use crate::{
types::{
content_key::state::StateContentKey,
enr::Enr,
ping_extensions::extension_types::PingExtensionType,
portal::{
AcceptInfo, DataRadius, FindContentInfo, FindNodesInfo, GetContentInfo,
PaginateLocalContentInfo, PongInfo, PutContentInfo, TraceContentInfo,
},
portal_wire::OfferTrace,
},
RawContentValue, RoutingTableInfo,
};
#[rpc(client, server, namespace = "portal")]
pub trait StateNetworkApi {
#[method(name = "stateRoutingTableInfo")]
async fn routing_table_info(&self) -> RpcResult<RoutingTableInfo>;
#[method(name = "stateRadius")]
async fn radius(&self) -> RpcResult<DataRadius>;
#[method(name = "stateAddEnr")]
async fn add_enr(&self, enr: Enr) -> RpcResult<bool>;
#[method(name = "stateGetEnr")]
async fn get_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
#[method(name = "stateDeleteEnr")]
async fn delete_enr(&self, node_id: NodeId) -> RpcResult<bool>;
#[method(name = "stateLookupEnr")]
async fn lookup_enr(&self, node_id: NodeId) -> RpcResult<Enr>;
#[method(name = "statePing")]
async fn ping(
&self,
enr: Enr,
payload_type: Option<PingExtensionType>,
payload: Option<Value>,
) -> RpcResult<PongInfo>;
#[method(name = "stateFindNodes")]
async fn find_nodes(&self, enr: Enr, distances: Vec<u16>) -> RpcResult<FindNodesInfo>;
#[method(name = "stateRecursiveFindNodes")]
async fn recursive_find_nodes(&self, node_id: NodeId) -> RpcResult<Vec<Enr>>;
#[method(name = "stateFindContent")]
async fn find_content(
&self,
enr: Enr,
content_key: StateContentKey,
) -> RpcResult<FindContentInfo>;
#[method(name = "stateGetContent")]
async fn get_content(&self, content_key: StateContentKey) -> RpcResult<GetContentInfo>;
#[method(name = "stateTraceGetContent")]
async fn trace_get_content(&self, content_key: StateContentKey) -> RpcResult<TraceContentInfo>;
#[method(name = "statePaginateLocalContentKeys")]
async fn paginate_local_content_keys(
&self,
offset: u64,
limit: u64,
) -> RpcResult<PaginateLocalContentInfo<StateContentKey>>;
#[method(name = "statePutContent")]
async fn put_content(
&self,
content_key: StateContentKey,
content_value: RawContentValue,
) -> RpcResult<PutContentInfo>;
#[method(name = "stateOffer")]
async fn offer(
&self,
enr: Enr,
content_items: Vec<(StateContentKey, RawContentValue)>,
) -> RpcResult<AcceptInfo>;
#[method(name = "stateTraceOffer")]
async fn trace_offer(
&self,
enr: Enr,
content_key: StateContentKey,
content_value: RawContentValue,
) -> RpcResult<OfferTrace>;
#[method(name = "stateStore")]
async fn store(
&self,
content_key: StateContentKey,
content_value: RawContentValue,
) -> RpcResult<bool>;
#[method(name = "stateLocalContent")]
async fn local_content(&self, content_key: StateContentKey) -> RpcResult<RawContentValue>;
}