Skip to main content

espresso_api/v1/
light_client.rs

1//! V1 light-client API.
2//!
3//! Mirrors the tide-disco endpoints defined in `crates/espresso/node/api/light-client.toml`.
4
5use async_trait::async_trait;
6use serde::Serialize;
7
8#[derive(Debug, Clone)]
9pub enum LeafQuery {
10    Height(u64),
11    Hash(String),
12    BlockHash(String),
13    PayloadHash(String),
14}
15
16#[derive(Debug, Clone)]
17pub enum HeaderQuery {
18    Height(u64),
19    Hash(String),
20    PayloadHash(String),
21}
22
23#[async_trait]
24pub trait LightClientApi {
25    type LeafProof: Serialize + Send + Sync + 'static;
26    type HeaderProof: Serialize + Send + Sync + 'static;
27    type StakeTableEvents: Serialize + Send + Sync + 'static;
28    type PayloadProof: Serialize + Send + Sync + 'static;
29    type NamespaceProof: Serialize + Send + Sync + 'static;
30
31    async fn get_leaf_proof(
32        &self,
33        query: LeafQuery,
34        finalized: Option<u64>,
35    ) -> anyhow::Result<Self::LeafProof>;
36
37    async fn get_header_proof(
38        &self,
39        root: u64,
40        requested: HeaderQuery,
41    ) -> anyhow::Result<Self::HeaderProof>;
42
43    async fn get_light_client_stake_table(
44        &self,
45        epoch: u64,
46    ) -> anyhow::Result<Self::StakeTableEvents>;
47
48    async fn get_payload_proof(&self, height: u64) -> anyhow::Result<Self::PayloadProof>;
49
50    async fn get_payload_proof_range(
51        &self,
52        start: u64,
53        end: u64,
54    ) -> anyhow::Result<Vec<Self::PayloadProof>>;
55
56    async fn get_lc_namespace_proof(
57        &self,
58        height: u64,
59        namespace: u64,
60    ) -> anyhow::Result<Self::NamespaceProof>;
61
62    async fn get_lc_namespace_proof_range(
63        &self,
64        start: u64,
65        end: u64,
66        namespace: u64,
67    ) -> anyhow::Result<Vec<Self::NamespaceProof>>;
68}