hotshot_query_service/explorer/
data_source.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the HotShot Query Service library.
3//
4// This program is free software: you can redistribute it and/or modify it under the terms of the GNU
5// General Public License as published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9// General Public License for more details.
10// You should have received a copy of the GNU General Public License along with this program. If not,
11// see <https://www.gnu.org/licenses/>.
12
13use async_trait::async_trait;
14use hotshot_types::traits::node_implementation::NodeType;
15use tagged_base64::TaggedBase64;
16
17use super::{
18    query_data::{
19        BlockDetail, BlockIdentifier, BlockSummary, ExplorerSummary, GetBlockDetailError,
20        GetBlockSummariesError, GetBlockSummariesRequest, GetExplorerSummaryError,
21        GetSearchResultsError, GetTransactionDetailError, GetTransactionSummariesError,
22        GetTransactionSummariesRequest, SearchResult, TransactionDetailResponse,
23        TransactionIdentifier, TransactionSummary,
24    },
25    traits::{ExplorerHeader, ExplorerTransaction},
26};
27use crate::{
28    availability::{QueryableHeader, QueryablePayload},
29    Header, Payload, Transaction,
30};
31
32/// An interface for querying Data and Statistics from the HotShot Blockchain.
33///
34/// This interface provides methods that allows the enabling of querying data
35/// concerning the blockchain from the stored data for use with a
36/// block explorer.  It does not provide the same guarantees as the
37/// Availability data source with data fetching.  It is not concerned with
38/// being up-to-date or having all of the data required, but rather it is
39/// concerned with providing the requested data as quickly as possible, and in
40/// a way that can be easily cached.
41#[async_trait]
42pub trait ExplorerDataSource<Types>
43where
44    Types: NodeType,
45    Header<Types>: ExplorerHeader<Types> + QueryableHeader<Types>,
46    Transaction<Types>: ExplorerTransaction<Types>,
47    Payload<Types>: QueryablePayload<Types>,
48{
49    /// `get_block_detail` is a method that retrieves the details of a specific
50    /// block from the blockchain.  The block is identified by the given
51    /// [BlockIdentifier].
52    async fn get_block_detail(
53        &self,
54        request: BlockIdentifier<Types>,
55    ) -> Result<BlockDetail<Types>, GetBlockDetailError>;
56
57    /// `get_block_summaries` is a method that retrieves a list of block
58    /// summaries from the blockchain.  The list is generated from the given
59    /// [GetBlockSummariesRequest].
60    async fn get_block_summaries(
61        &self,
62        request: GetBlockSummariesRequest<Types>,
63    ) -> Result<Vec<BlockSummary<Types>>, GetBlockSummariesError>;
64
65    /// `get_transaction_detail` is a method that retrieves the details of a
66    /// specific transaction from the blockchain.  The transaction is identified
67    /// by the given [TransactionIdentifier].
68    async fn get_transaction_detail(
69        &self,
70        request: TransactionIdentifier<Types>,
71    ) -> Result<TransactionDetailResponse<Types>, GetTransactionDetailError>;
72
73    /// `get_transaction_summaries` is a method that retrieves a list of
74    /// transaction summaries from the blockchain.  The list is generated from
75    /// the given [GetTransactionSummariesRequest].
76    async fn get_transaction_summaries(
77        &self,
78        request: GetTransactionSummariesRequest<Types>,
79    ) -> Result<Vec<TransactionSummary<Types>>, GetTransactionSummariesError>;
80
81    /// `get_explorer_summary` is a method that retrieves a summary overview of
82    /// the blockchain.  This is useful for displaying information that
83    /// indicates the overall status of the block chain.
84    async fn get_explorer_summary(&self)
85        -> Result<ExplorerSummary<Types>, GetExplorerSummaryError>;
86
87    /// `get_search_results` is a method that retrieves the results of a search
88    /// query against the blockchain.  The results are generated from the given
89    /// query string.
90    async fn get_search_results(
91        &self,
92        query: TaggedBase64,
93    ) -> Result<SearchResult<Types>, GetSearchResultsError>;
94}