1use std::collections::HashMap;
7
8use alloy::primitives::Address;
9use async_trait::async_trait;
10use espresso_types::{
11 PubKey, SeqTypes,
12 v0_3::{AuthenticatedValidator, RegisteredValidator, RewardAmount},
13};
14use hotshot_query_service_types::{
15 Header,
16 availability::{BlockQueryData, LeafQueryData},
17 node::{Limits, SyncStatusQueryData, TimeWindowQueryData},
18};
19use hotshot_types::{
20 PeerConfig,
21 data::{EpochNumber, VidShare},
22 traits::node_implementation::NodeType,
23};
24use indexmap::IndexMap;
25use serde::{Deserialize, Serialize};
26
27#[derive(Debug, Clone)]
28pub enum VidShareId {
29 Height(u64),
30 Hash(String),
31 PayloadHash(String),
32}
33
34#[derive(Debug, Clone)]
35pub enum HeaderWindowStart {
36 Time(u64),
37 Height(u64),
38 Hash(String),
39}
40
41#[derive(Serialize, Deserialize)]
42#[serde(bound = "T: NodeType")]
43pub struct StakeTableWithEpochNumber<T: NodeType> {
44 pub epoch: Option<EpochNumber>,
45 pub stake_table: Vec<PeerConfig<T>>,
46}
47
48#[async_trait]
49pub trait NodeApi {
50 async fn block_height(&self) -> anyhow::Result<u64>;
51
52 async fn count_transactions(
53 &self,
54 from: Option<u64>,
55 to: Option<u64>,
56 namespace: Option<u64>,
57 ) -> anyhow::Result<u64>;
58
59 async fn payload_size(
60 &self,
61 from: Option<u64>,
62 to: Option<u64>,
63 namespace: Option<u64>,
64 ) -> anyhow::Result<u64>;
65
66 async fn get_vid_share(&self, id: VidShareId) -> anyhow::Result<VidShare>;
67
68 async fn sync_status(&self) -> anyhow::Result<SyncStatusQueryData>;
69
70 async fn get_header_window(
71 &self,
72 start: HeaderWindowStart,
73 end: u64,
74 ) -> anyhow::Result<TimeWindowQueryData<Header<SeqTypes>>>;
75
76 async fn limits(&self) -> anyhow::Result<Limits>;
77
78 async fn stake_table(&self, epoch: u64) -> anyhow::Result<Vec<PeerConfig<SeqTypes>>>;
79 async fn stake_table_current(&self) -> anyhow::Result<StakeTableWithEpochNumber<SeqTypes>>;
80 async fn da_stake_table(&self, epoch: u64) -> anyhow::Result<Vec<PeerConfig<SeqTypes>>>;
81 async fn da_stake_table_current(&self) -> anyhow::Result<StakeTableWithEpochNumber<SeqTypes>>;
82
83 async fn get_validators(
84 &self,
85 epoch: u64,
86 ) -> anyhow::Result<IndexMap<Address, AuthenticatedValidator<PubKey>>>;
87 async fn get_all_validators(
88 &self,
89 epoch: u64,
90 offset: u64,
91 limit: u64,
92 ) -> anyhow::Result<Vec<RegisteredValidator<PubKey>>>;
93
94 async fn current_proposal_participation(&self) -> anyhow::Result<HashMap<PubKey, f64>>;
95 async fn proposal_participation(&self, epoch: u64) -> anyhow::Result<HashMap<PubKey, f64>>;
96 async fn current_vote_participation(&self) -> anyhow::Result<HashMap<PubKey, f64>>;
97 async fn vote_participation(&self, epoch: u64) -> anyhow::Result<HashMap<PubKey, f64>>;
98
99 async fn get_block_reward(&self, epoch: Option<u64>) -> anyhow::Result<Option<RewardAmount>>;
100
101 async fn get_oldest_block(&self) -> anyhow::Result<Option<BlockQueryData<SeqTypes>>>;
102 async fn get_oldest_leaf(&self) -> anyhow::Result<Option<LeafQueryData<SeqTypes>>>;
103}