Skip to main content

espresso_api/v1/
node.rs

1//! V1 node API.
2//!
3//! Mirrors the tide-disco endpoints defined in `hotshot-query-service/api/node.toml`
4//! and `crates/espresso/node/api/node.toml`.
5
6use async_trait::async_trait;
7use serde::Serialize;
8
9#[derive(Debug, Clone)]
10pub enum VidShareId {
11    Height(u64),
12    Hash(String),
13    PayloadHash(String),
14}
15
16#[derive(Debug, Clone)]
17pub enum HeaderWindowStart {
18    Time(u64),
19    Height(u64),
20    Hash(String),
21}
22
23#[async_trait]
24pub trait NodeApi {
25    type VidShare: Serialize + Send + Sync + 'static;
26    type SyncStatus: Serialize + Send + Sync + 'static;
27    type HeaderWindow: Serialize + Send + Sync + 'static;
28    type Limits: Serialize + Send + Sync + 'static;
29    type StakeTable: Serialize + Send + Sync + 'static;
30    type StakeTableCurrent: Serialize + Send + Sync + 'static;
31    type Validators: Serialize + Send + Sync + 'static;
32    type AllValidators: Serialize + Send + Sync + 'static;
33    type Participation: Serialize + Send + Sync + 'static;
34    type BlockReward: Serialize + Send + Sync + 'static;
35    type Block: Serialize + Send + Sync + 'static;
36    type Leaf: Serialize + Send + Sync + 'static;
37
38    async fn block_height(&self) -> anyhow::Result<u64>;
39
40    async fn count_transactions(
41        &self,
42        from: Option<u64>,
43        to: Option<u64>,
44        namespace: Option<u64>,
45    ) -> anyhow::Result<u64>;
46
47    async fn payload_size(
48        &self,
49        from: Option<u64>,
50        to: Option<u64>,
51        namespace: Option<u64>,
52    ) -> anyhow::Result<u64>;
53
54    async fn get_vid_share(&self, id: VidShareId) -> anyhow::Result<Self::VidShare>;
55
56    async fn sync_status(&self) -> anyhow::Result<Self::SyncStatus>;
57
58    async fn get_header_window(
59        &self,
60        start: HeaderWindowStart,
61        end: u64,
62    ) -> anyhow::Result<Self::HeaderWindow>;
63
64    async fn limits(&self) -> anyhow::Result<Self::Limits>;
65
66    async fn stake_table(&self, epoch: u64) -> anyhow::Result<Self::StakeTable>;
67    async fn stake_table_current(&self) -> anyhow::Result<Self::StakeTableCurrent>;
68    async fn da_stake_table(&self, epoch: u64) -> anyhow::Result<Self::StakeTable>;
69    async fn da_stake_table_current(&self) -> anyhow::Result<Self::StakeTableCurrent>;
70
71    async fn get_validators(&self, epoch: u64) -> anyhow::Result<Self::Validators>;
72    async fn get_all_validators(
73        &self,
74        epoch: u64,
75        offset: u64,
76        limit: u64,
77    ) -> anyhow::Result<Self::AllValidators>;
78
79    async fn current_proposal_participation(&self) -> anyhow::Result<Self::Participation>;
80    async fn proposal_participation(&self, epoch: u64) -> anyhow::Result<Self::Participation>;
81    async fn current_vote_participation(&self) -> anyhow::Result<Self::Participation>;
82    async fn vote_participation(&self, epoch: u64) -> anyhow::Result<Self::Participation>;
83
84    async fn get_block_reward(&self, epoch: Option<u64>) -> anyhow::Result<Self::BlockReward>;
85
86    async fn get_oldest_block(&self) -> anyhow::Result<Option<Self::Block>>;
87    async fn get_oldest_leaf(&self) -> anyhow::Result<Option<Self::Leaf>>;
88}