Skip to main content

espresso_api/v1/
merklized_state.rs

1//! V1 merklized state APIs (block-state and fee-state).
2//!
3//! Mirrors the tide-disco endpoints defined in `hotshot-query-service/api/state.toml`
4//! and `crates/espresso/node/api/fee.toml`.
5
6use async_trait::async_trait;
7use serde::Serialize;
8
9#[derive(Debug, Clone)]
10pub enum Snapshot {
11    Height(u64),
12    Commit(String),
13}
14
15#[async_trait]
16pub trait BlockStateApi {
17    type MerkleProof: Serialize + Send + Sync + 'static;
18
19    async fn get_block_state_path(
20        &self,
21        snapshot: Snapshot,
22        key: String,
23    ) -> anyhow::Result<Self::MerkleProof>;
24
25    async fn get_block_state_height(&self) -> anyhow::Result<u64>;
26}
27
28#[async_trait]
29pub trait FeeStateApi {
30    type MerkleProof: Serialize + Send + Sync + 'static;
31    type FeeAmount: Serialize + Send + Sync + 'static;
32
33    async fn get_fee_state_path(
34        &self,
35        snapshot: Snapshot,
36        key: String,
37    ) -> anyhow::Result<Self::MerkleProof>;
38
39    async fn get_fee_state_height(&self) -> anyhow::Result<u64>;
40
41    async fn get_fee_balance_latest(
42        &self,
43        address: String,
44    ) -> anyhow::Result<Option<Self::FeeAmount>>;
45}