1use std::collections::BTreeMap;
6
7use fastcrypto::traits::ToFromBytes;
8use iota_types::{
9 base_types::{AuthorityName, EpochId, ObjectID},
10 committee::Committee,
11 iota_serde::BigInt,
12 iota_system_state::iota_system_state_summary::IotaValidatorSummary,
13 messages_checkpoint::CheckpointSequenceNumber,
14};
15use move_core_types::identifier::Identifier;
16use schemars::JsonSchema;
17use serde::{Deserialize, Serialize};
18use serde_with::{DisplayFromStr, serde_as};
19
20use crate::Page;
21
22pub type EpochPage = Page<EpochInfo, BigInt<u64>>;
23pub type EpochMetricsPage = Page<EpochMetrics, BigInt<u64>>;
24
25#[serde_as]
26#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
27#[serde(rename_all = "camelCase")]
28pub struct EpochInfo {
29 #[schemars(with = "BigInt<u64>")]
31 #[serde_as(as = "BigInt<u64>")]
32 pub epoch: EpochId,
33 pub validators: Vec<IotaValidatorSummary>,
35 #[schemars(with = "BigInt<u64>")]
37 #[serde_as(as = "BigInt<u64>")]
38 pub epoch_total_transactions: u64,
39 #[schemars(with = "BigInt<u64>")]
41 #[serde_as(as = "BigInt<u64>")]
42 pub first_checkpoint_id: CheckpointSequenceNumber,
43 #[schemars(with = "BigInt<u64>")]
45 #[serde_as(as = "BigInt<u64>")]
46 pub epoch_start_timestamp: u64,
47 pub end_of_epoch_info: Option<EndOfEpochInfo>,
49 pub reference_gas_price: Option<u64>,
51 #[schemars(with = "Vec<BigInt<u64>>")]
54 #[serde_as(as = "Vec<BigInt<u64>>")]
55 #[serde(skip_serializing_if = "Vec::is_empty")]
56 #[serde(default)]
57 pub committee_members: Vec<u64>,
58}
59
60impl EpochInfo {
61 pub fn committee(&self) -> Result<Committee, fastcrypto::error::FastCryptoError> {
62 let mut voting_rights = BTreeMap::new();
63 for &i in &self.committee_members {
64 let validator = self
65 .validators
66 .get(i as usize)
67 .expect("validators should include committee members");
68 let name = AuthorityName::from_bytes(&validator.authority_pubkey_bytes)?;
69 voting_rights.insert(name, validator.voting_power);
70 }
71 Ok(Committee::new(self.epoch, voting_rights))
72 }
73}
74
75#[serde_as]
77#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
78#[serde(rename_all = "camelCase")]
79pub struct EpochMetrics {
80 #[schemars(with = "BigInt<u64>")]
82 #[serde_as(as = "BigInt<u64>")]
83 pub epoch: EpochId,
84 #[schemars(with = "BigInt<u64>")]
86 #[serde_as(as = "BigInt<u64>")]
87 pub epoch_total_transactions: u64,
88 #[schemars(with = "BigInt<u64>")]
90 #[serde_as(as = "BigInt<u64>")]
91 pub first_checkpoint_id: CheckpointSequenceNumber,
92 #[schemars(with = "BigInt<u64>")]
94 #[serde_as(as = "BigInt<u64>")]
95 pub epoch_start_timestamp: u64,
96 pub end_of_epoch_info: Option<EndOfEpochInfo>,
98}
99
100#[serde_as]
101#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
102#[serde(rename_all = "camelCase")]
103pub struct EndOfEpochInfo {
104 #[schemars(with = "BigInt<u64>")]
105 #[serde_as(as = "BigInt<u64>")]
106 pub last_checkpoint_id: CheckpointSequenceNumber,
107 #[schemars(with = "BigInt<u64>")]
108 #[serde_as(as = "BigInt<u64>")]
109 pub epoch_end_timestamp: u64,
110 #[schemars(with = "BigInt<u64>")]
112 #[serde_as(as = "BigInt<u64>")]
113 pub protocol_version: u64,
114 #[schemars(with = "BigInt<u64>")]
115 #[serde_as(as = "BigInt<u64>")]
116 pub reference_gas_price: u64,
117 #[schemars(with = "BigInt<u64>")]
118 #[serde_as(as = "BigInt<u64>")]
119 pub total_stake: u64,
120 #[schemars(with = "BigInt<u64>")]
121 #[serde_as(as = "BigInt<u64>")]
122 pub storage_charge: u64,
123 #[schemars(with = "BigInt<u64>")]
124 #[serde_as(as = "BigInt<u64>")]
125 pub storage_rebate: u64,
126 #[schemars(with = "BigInt<u64>")]
127 #[serde_as(as = "BigInt<u64>")]
128 pub storage_fund_balance: u64,
129 #[schemars(with = "BigInt<u64>")]
130 #[serde_as(as = "BigInt<u64>")]
131 pub total_gas_fees: u64,
132 #[schemars(with = "BigInt<u64>")]
133 #[serde_as(as = "BigInt<u64>")]
134 pub total_stake_rewards_distributed: u64,
135 #[schemars(with = "BigInt<u64>")]
136 #[serde_as(as = "BigInt<u64>")]
137 pub burnt_tokens_amount: u64,
138 #[schemars(with = "BigInt<u64>")]
139 #[serde_as(as = "BigInt<u64>")]
140 pub minted_tokens_amount: u64,
141}
142
143#[serde_as]
144#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
145#[serde(rename_all = "camelCase")]
146pub struct NetworkMetrics {
147 pub current_tps: f64,
149 pub tps_30_days: f64,
151 #[schemars(with = "BigInt<u64>")]
153 #[serde_as(as = "BigInt<u64>")]
154 pub total_packages: u64,
155 #[schemars(with = "BigInt<u64>")]
157 #[serde_as(as = "BigInt<u64>")]
158 pub total_addresses: u64,
159 #[schemars(with = "BigInt<u64>")]
161 #[serde_as(as = "BigInt<u64>")]
162 pub total_objects: u64,
163 #[schemars(with = "BigInt<u64>")]
165 #[serde_as(as = "BigInt<u64>")]
166 pub current_epoch: u64,
167 #[schemars(with = "BigInt<u64>")]
169 #[serde_as(as = "BigInt<u64>")]
170 pub current_checkpoint: u64,
171}
172
173#[serde_as]
174#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
175#[serde(rename_all = "camelCase")]
176pub struct MoveCallMetrics {
177 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
179 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
180 pub rank_3_days: Vec<(MoveFunctionName, usize)>,
181 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
183 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
184 pub rank_7_days: Vec<(MoveFunctionName, usize)>,
185 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
187 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
188 pub rank_30_days: Vec<(MoveFunctionName, usize)>,
189}
190
191#[serde_as]
193#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
194#[serde(rename_all = "camelCase")]
195pub struct MoveFunctionName {
196 pub package: ObjectID,
198 #[schemars(with = "String")]
200 #[serde_as(as = "DisplayFromStr")]
201 pub module: Identifier,
202 #[schemars(with = "String")]
204 #[serde_as(as = "DisplayFromStr")]
205 pub function: Identifier,
206}
207
208#[serde_as]
210#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
211#[serde(rename_all = "camelCase")]
212pub struct AddressMetrics {
213 pub checkpoint: u64,
215 pub epoch: u64,
217 pub timestamp_ms: u64,
219 pub cumulative_addresses: u64,
221 pub cumulative_active_addresses: u64,
223 pub daily_active_addresses: u64,
225}
226
227#[serde_as]
229#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
230#[serde(rename_all = "camelCase")]
231pub struct ParticipationMetrics {
232 pub total_addresses: u64,
234}