espresso_api/v1/
availability.rs1use 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<Option<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#[async_trait]
70pub trait HotShotAvailabilityApi {
71 type Leaf: Serialize + Send + Sync + 'static;
72 type Block: Serialize + Send + Sync + 'static;
73 type Header: Serialize + Send + Sync + 'static;
74 type Payload: Serialize + Send + Sync + 'static;
75 type VidCommon: Serialize + Send + Sync + 'static;
76 type Transaction: Serialize + Send + Sync + 'static;
77 type TransactionWithProof: Serialize + Send + Sync + 'static;
78 type BlockSummary: Serialize + Send + Sync + 'static;
79 type Limits: Serialize + Send + Sync + 'static;
80 type Cert2: Serialize + Send + Sync + 'static;
81
82 async fn get_leaf(&self, id: LeafId) -> anyhow::Result<Self::Leaf>;
83 async fn get_leaf_range(&self, from: usize, until: usize) -> anyhow::Result<Vec<Self::Leaf>>;
84
85 async fn get_header(&self, id: BlockId) -> anyhow::Result<Self::Header>;
86 async fn get_header_range(
87 &self,
88 from: usize,
89 until: usize,
90 ) -> anyhow::Result<Vec<Self::Header>>;
91
92 async fn get_block(&self, id: BlockId) -> anyhow::Result<Self::Block>;
93 async fn get_block_range(&self, from: usize, until: usize) -> anyhow::Result<Vec<Self::Block>>;
94
95 async fn get_payload(&self, id: PayloadId) -> anyhow::Result<Self::Payload>;
96 async fn get_payload_range(
97 &self,
98 from: usize,
99 until: usize,
100 ) -> anyhow::Result<Vec<Self::Payload>>;
101
102 async fn get_vid_common(&self, id: BlockId) -> anyhow::Result<Self::VidCommon>;
103 async fn get_vid_common_range(
104 &self,
105 from: usize,
106 until: usize,
107 ) -> anyhow::Result<Vec<Self::VidCommon>>;
108
109 async fn get_transaction_by_position(
110 &self,
111 height: u64,
112 index: u64,
113 ) -> anyhow::Result<Self::Transaction>;
114 async fn get_transaction_by_hash(&self, hash: String) -> anyhow::Result<Self::Transaction>;
115
116 async fn get_transaction_proof_by_position(
117 &self,
118 height: u64,
119 index: u64,
120 ) -> anyhow::Result<Self::TransactionWithProof>;
121 async fn get_transaction_proof_by_hash(
122 &self,
123 hash: String,
124 ) -> anyhow::Result<Self::TransactionWithProof>;
125
126 async fn get_block_summary(&self, height: usize) -> anyhow::Result<Self::BlockSummary>;
127 async fn get_block_summary_range(
128 &self,
129 from: usize,
130 until: usize,
131 ) -> anyhow::Result<Vec<Self::BlockSummary>>;
132
133 async fn get_limits(&self) -> anyhow::Result<Self::Limits>;
134
135 async fn get_cert2(&self, height: u64) -> anyhow::Result<Option<Self::Cert2>>;
136
137 async fn stream_leaves(&self, from: usize) -> anyhow::Result<BoxStream<'static, Self::Leaf>>;
138
139 async fn stream_headers(&self, from: usize)
140 -> anyhow::Result<BoxStream<'static, Self::Header>>;
141
142 async fn stream_blocks(&self, from: usize) -> anyhow::Result<BoxStream<'static, Self::Block>>;
143
144 async fn stream_payloads(
145 &self,
146 from: usize,
147 ) -> anyhow::Result<BoxStream<'static, Self::Payload>>;
148
149 async fn stream_vid_common(
150 &self,
151 from: usize,
152 ) -> anyhow::Result<BoxStream<'static, Self::VidCommon>>;
153
154 async fn stream_transactions(
155 &self,
156 from: usize,
157 namespace: Option<u32>,
158 ) -> anyhow::Result<BoxStream<'static, Self::Transaction>>;
159}