Skip to main content

espresso_api/v1/
explorer.rs

1//! V1 explorer API.
2//!
3//! Mirrors the endpoints of the legacy `hotshot-query-service` explorer API (its tide-disco
4//! `explorer.toml`, since removed).
5
6use async_trait::async_trait;
7use espresso_types::SeqTypes;
8use hotshot_query_service_types::explorer::response::{
9    BlockDetailResponse, BlockSummaryResponse, ExplorerSummaryResponse, SearchResultResponse,
10    TransactionDetailResponse, TransactionSummariesResponse,
11};
12
13#[derive(Debug, Clone)]
14pub enum BlockIdent {
15    Height(u64),
16    Hash(String),
17    Latest,
18}
19
20#[derive(Debug, Clone)]
21pub enum TxIdent {
22    HeightAndOffset(u64, u64),
23    Hash(String),
24    Latest,
25}
26
27#[derive(Debug, Clone)]
28pub enum TxSummaryFilter {
29    None,
30    Block(u64),
31    Namespace(i64),
32}
33
34#[async_trait]
35pub trait ExplorerApi {
36    async fn get_block_detail(
37        &self,
38        ident: BlockIdent,
39    ) -> anyhow::Result<BlockDetailResponse<SeqTypes>>;
40
41    async fn get_block_summaries(
42        &self,
43        target: BlockIdent,
44        limit: u64,
45    ) -> anyhow::Result<BlockSummaryResponse<SeqTypes>>;
46
47    async fn get_transaction_detail(
48        &self,
49        ident: TxIdent,
50    ) -> anyhow::Result<TransactionDetailResponse<SeqTypes>>;
51
52    async fn get_transaction_summaries(
53        &self,
54        target: TxIdent,
55        limit: u64,
56        filter: TxSummaryFilter,
57    ) -> anyhow::Result<TransactionSummariesResponse<SeqTypes>>;
58
59    async fn get_explorer_summary(&self) -> anyhow::Result<ExplorerSummaryResponse<SeqTypes>>;
60
61    async fn get_search_result(
62        &self,
63        query: String,
64    ) -> anyhow::Result<SearchResultResponse<SeqTypes>>;
65}