hotshot_query_service/explorer/
traits.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 std::fmt::Debug;
14
15use hotshot_types::traits::node_implementation::NodeType;
16use serde::{de::DeserializeOwned, Serialize};
17
18use crate::{
19    availability::{NamespaceId, QueryableHeader},
20    Header,
21};
22
23/// [ExplorerHeader] is a trait that represents certain extensions to the
24/// [BlockHeader] that are specific to the Block Explorer API.  This trait
25/// allows for the explorer module to be defined and provide an API for any
26/// consuming Block Explorer.
27pub trait ExplorerHeader<Types: NodeType>: QueryableHeader<Types>
28where
29    Header<Types>: QueryableHeader<Types>,
30{
31    /// BalanceAmount is a type that represents a general balance amount.  It
32    /// does not indicate how this balance is represented, just that there is
33    /// a representation of it that adheres to the trait restrictions specified.
34    type BalanceAmount: Clone + Debug + Serialize + DeserializeOwned + Send + Sync + PartialEq + Eq;
35
36    /// WalletAddress is a type that represents the address of a Wallet.  It
37    /// does not indicate how this address is represented, just that there is
38    /// a representation of it that adheres to the trait restrictions specified.
39    type WalletAddress: Clone + Debug + Serialize + DeserializeOwned + Send + Sync + PartialEq + Eq;
40
41    /// ProposerId is a type that represents the proposer id of the block.  It
42    /// does not indicate how this proposer id is represented, just that there is
43    /// a representation of it that adheres to the trait restrictions specified.
44    type ProposerId: Clone + Debug + Serialize + DeserializeOwned + Send + Sync + PartialEq + Eq;
45
46    /// The proposer id of the block as stored within the block header.
47    fn proposer_id(&self) -> Self::ProposerId;
48
49    /// The wallet address of the fee info account contained within the block
50    /// header.
51    fn fee_info_account(&self) -> Self::WalletAddress;
52
53    /// The balance amount of the fee info contained within the block header.
54    fn fee_info_balance(&self) -> Self::BalanceAmount;
55
56    /// The balance amount of the reward for constructing the block.
57    fn reward_balance(&self) -> Self::BalanceAmount;
58
59    /// A collection of namespace ids that are contained within the block header.
60    fn namespace_ids(&self) -> Vec<NamespaceId<Types>>;
61}
62
63/// ExplorerTransaction is a trait that allows the Explorer API to be able to
64/// retrieve a namespace id from a transaction.  This is necessary for the
65/// Explorer API to be able to display the namespace id for a
66/// TransactionSummary.
67pub trait ExplorerTransaction<Types>
68where
69    Types: NodeType,
70    Header<Types>: QueryableHeader<Types>,
71{
72    /// namespace_id returns the namespace id of the individual transaction.
73    fn namespace_id(&self) -> NamespaceId<Types>;
74
75    /// payload_size returns the size of the payload of the transaction.
76    fn payload_size(&self) -> u64;
77}