Skip to main content

espresso_api/v1/
availability.rs

1use async_trait::async_trait;
2use futures::stream::BoxStream;
3use serde::Serialize;
4
5#[derive(Debug, Clone)]
6pub enum BlockId {
7    Height(u64),
8    Hash(String),
9    PayloadHash(String),
10}
11
12#[derive(Debug, Clone)]
13pub enum LeafId {
14    Height(u64),
15    Hash(String),
16}
17
18#[derive(Debug, Clone)]
19pub enum PayloadId {
20    Height(u64),
21    Hash(String),
22    BlockHash(String),
23}
24
25#[async_trait]
26pub trait AvailabilityApi {
27    type NamespaceProofQueryData: Serialize + Send + Sync + 'static;
28
29    type IncorrectEncodingProof: Serialize + Send + Sync;
30
31    type StateCertQueryDataV1: Serialize + Send + Sync;
32
33    type StateCertQueryDataV2: Serialize + Send + Sync;
34
35    async fn get_namespace_proof(
36        &self,
37        block_id: BlockId,
38        namespace: u32,
39    ) -> anyhow::Result<Self::NamespaceProofQueryData>;
40
41    async fn get_namespace_proof_range(
42        &self,
43        from: u64,
44        until: u64,
45        namespace: u32,
46    ) -> anyhow::Result<Vec<Self::NamespaceProofQueryData>>;
47
48    async fn stream_namespace_proofs(
49        &self,
50        from: usize,
51        namespace: u32,
52    ) -> anyhow::Result<BoxStream<'static, Self::NamespaceProofQueryData>>;
53
54    async fn get_incorrect_encoding_proof(
55        &self,
56        block_id: BlockId,
57        namespace: u32,
58    ) -> anyhow::Result<Self::IncorrectEncodingProof>;
59
60    async fn get_state_cert(&self, epoch: u64) -> anyhow::Result<Self::StateCertQueryDataV1>;
61
62    async fn get_state_cert_v2(&self, epoch: u64) -> anyhow::Result<Self::StateCertQueryDataV2>;
63}
64
65/// HotShot core availability API: mirrors the hotshot-query-service availability endpoints.
66///
67/// Each method corresponds to a hotshot-query-service route, with no path or output changes.
68#[async_trait]
69pub trait HotShotAvailabilityApi {
70    type Leaf: Serialize + Send + Sync + 'static;
71    type Block: Serialize + Send + Sync + 'static;
72    type Header: Serialize + Send + Sync + 'static;
73    type Payload: Serialize + Send + Sync + 'static;
74    type VidCommon: Serialize + Send + Sync + 'static;
75    type Transaction: Serialize + Send + Sync + 'static;
76    type TransactionWithProof: Serialize + Send + Sync + 'static;
77    type BlockSummary: Serialize + Send + Sync + 'static;
78    type Limits: Serialize + Send + Sync + 'static;
79    type Cert2: Serialize + Send + Sync + 'static;
80
81    async fn get_leaf(&self, id: LeafId) -> anyhow::Result<Self::Leaf>;
82    async fn get_leaf_range(&self, from: usize, until: usize) -> anyhow::Result<Vec<Self::Leaf>>;
83
84    async fn get_header(&self, id: BlockId) -> anyhow::Result<Self::Header>;
85    async fn get_header_range(
86        &self,
87        from: usize,
88        until: usize,
89    ) -> anyhow::Result<Vec<Self::Header>>;
90
91    async fn get_block(&self, id: BlockId) -> anyhow::Result<Self::Block>;
92    async fn get_block_range(&self, from: usize, until: usize) -> anyhow::Result<Vec<Self::Block>>;
93
94    async fn get_payload(&self, id: PayloadId) -> anyhow::Result<Self::Payload>;
95    async fn get_payload_range(
96        &self,
97        from: usize,
98        until: usize,
99    ) -> anyhow::Result<Vec<Self::Payload>>;
100
101    async fn get_vid_common(&self, id: BlockId) -> anyhow::Result<Self::VidCommon>;
102    async fn get_vid_common_range(
103        &self,
104        from: usize,
105        until: usize,
106    ) -> anyhow::Result<Vec<Self::VidCommon>>;
107
108    async fn get_transaction_by_position(
109        &self,
110        height: u64,
111        index: u64,
112    ) -> anyhow::Result<Self::Transaction>;
113    async fn get_transaction_by_hash(&self, hash: String) -> anyhow::Result<Self::Transaction>;
114
115    async fn get_transaction_proof_by_position(
116        &self,
117        height: u64,
118        index: u64,
119    ) -> anyhow::Result<Self::TransactionWithProof>;
120    async fn get_transaction_proof_by_hash(
121        &self,
122        hash: String,
123    ) -> anyhow::Result<Self::TransactionWithProof>;
124
125    async fn get_block_summary(&self, height: usize) -> anyhow::Result<Self::BlockSummary>;
126    async fn get_block_summary_range(
127        &self,
128        from: usize,
129        until: usize,
130    ) -> anyhow::Result<Vec<Self::BlockSummary>>;
131
132    async fn get_limits(&self) -> anyhow::Result<Self::Limits>;
133
134    async fn get_cert2(&self, height: u64) -> anyhow::Result<Option<Self::Cert2>>;
135
136    async fn stream_leaves(&self, from: usize) -> anyhow::Result<BoxStream<'static, Self::Leaf>>;
137
138    async fn stream_headers(&self, from: usize)
139    -> anyhow::Result<BoxStream<'static, Self::Header>>;
140
141    async fn stream_blocks(&self, from: usize) -> anyhow::Result<BoxStream<'static, Self::Block>>;
142
143    async fn stream_payloads(
144        &self,
145        from: usize,
146    ) -> anyhow::Result<BoxStream<'static, Self::Payload>>;
147
148    async fn stream_vid_common(
149        &self,
150        from: usize,
151    ) -> anyhow::Result<BoxStream<'static, Self::VidCommon>>;
152
153    async fn stream_transactions(
154        &self,
155        from: usize,
156        namespace: Option<u32>,
157    ) -> anyhow::Result<BoxStream<'static, Self::Transaction>>;
158}