Skip to main content

espresso_api/v1/
merklized_state.rs

1//! V1 merklized state APIs (block-state and fee-state).
2//!
3//! Mirrors the endpoints of the legacy `hotshot-query-service` merklized-state API (its
4//! tide-disco `state.toml`, since removed).
5
6use async_trait::async_trait;
7use committable::Commitment;
8use espresso_types::{BlockMerkleTree, FeeAccount, FeeAmount, FeeMerkleTree, Header};
9use jf_merkle_tree_compat::{
10    MerkleTreeScheme,
11    prelude::{MerkleProof, Sha3Node},
12};
13
14#[derive(Debug, Clone)]
15pub enum Snapshot {
16    Height(u64),
17    Commit(String),
18}
19
20pub type BlockStatePath = MerkleProof<
21    Commitment<Header>,
22    u64,
23    Sha3Node,
24    { <BlockMerkleTree as MerkleTreeScheme>::ARITY },
25>;
26
27pub type FeeStatePath =
28    MerkleProof<FeeAmount, FeeAccount, Sha3Node, { <FeeMerkleTree as MerkleTreeScheme>::ARITY }>;
29
30#[async_trait]
31pub trait BlockStateApi {
32    async fn get_block_state_path(
33        &self,
34        snapshot: Snapshot,
35        key: String,
36    ) -> anyhow::Result<BlockStatePath>;
37
38    async fn get_block_state_height(&self) -> anyhow::Result<u64>;
39}
40
41#[async_trait]
42pub trait FeeStateApi {
43    async fn get_fee_state_path(
44        &self,
45        snapshot: Snapshot,
46        key: String,
47    ) -> anyhow::Result<FeeStatePath>;
48
49    async fn get_fee_state_height(&self) -> anyhow::Result<u64>;
50
51    async fn get_fee_balance_latest(&self, address: String) -> anyhow::Result<Option<FeeAmount>>;
52}