1use std::collections::BTreeMap;
6
7use fastcrypto::traits::ToFromBytes;
8use iota_types::{
9 base_types::{AuthorityName, EpochId},
10 committee::Committee,
11 iota_serde::BigInt,
12 iota_system_state::iota_system_state_summary::IotaValidatorSummary,
13 messages_checkpoint::CheckpointSequenceNumber,
14};
15use schemars::JsonSchema;
16use serde::{Deserialize, Serialize};
17use serde_with::serde_as;
18
19use crate::{MoveFunctionName, Page};
20
21pub type EpochPage = Page<EpochInfo, BigInt<u64>>;
22pub type EpochMetricsPage = Page<EpochMetrics, BigInt<u64>>;
23
24#[serde_as]
25#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
26#[serde(rename_all = "camelCase")]
27pub struct EpochInfo {
28 #[schemars(with = "BigInt<u64>")]
30 #[serde_as(as = "BigInt<u64>")]
31 pub epoch: EpochId,
32 pub validators: Vec<IotaValidatorSummary>,
34 #[schemars(with = "BigInt<u64>")]
36 #[serde_as(as = "BigInt<u64>")]
37 pub epoch_total_transactions: u64,
38 #[schemars(with = "BigInt<u64>")]
40 #[serde_as(as = "BigInt<u64>")]
41 pub first_checkpoint_id: CheckpointSequenceNumber,
42 #[schemars(with = "BigInt<u64>")]
44 #[serde_as(as = "BigInt<u64>")]
45 pub epoch_start_timestamp: u64,
46 pub end_of_epoch_info: Option<EndOfEpochInfo>,
48 pub reference_gas_price: Option<u64>,
50 #[schemars(with = "Vec<BigInt<u64>>")]
53 #[serde_as(as = "Vec<BigInt<u64>>")]
54 #[serde(skip_serializing_if = "Vec::is_empty")]
55 #[serde(default)]
56 pub committee_members: Vec<u64>,
57}
58
59impl EpochInfo {
60 pub fn committee(&self) -> Result<Committee, fastcrypto::error::FastCryptoError> {
61 let mut voting_rights = BTreeMap::new();
62 for &i in &self.committee_members {
63 let validator = self
64 .validators
65 .get(i as usize)
66 .expect("validators should include committee members");
67 let name = AuthorityName::from_bytes(&validator.authority_pubkey_bytes)?;
68 voting_rights.insert(name, validator.voting_power);
69 }
70 Ok(Committee::new(self.epoch, voting_rights))
71 }
72}
73
74#[serde_as]
76#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
77#[serde(rename_all = "camelCase")]
78pub struct EpochMetrics {
79 #[schemars(with = "BigInt<u64>")]
81 #[serde_as(as = "BigInt<u64>")]
82 pub epoch: EpochId,
83 #[schemars(with = "BigInt<u64>")]
85 #[serde_as(as = "BigInt<u64>")]
86 pub epoch_total_transactions: u64,
87 #[schemars(with = "BigInt<u64>")]
89 #[serde_as(as = "BigInt<u64>")]
90 pub first_checkpoint_id: CheckpointSequenceNumber,
91 #[schemars(with = "BigInt<u64>")]
93 #[serde_as(as = "BigInt<u64>")]
94 pub epoch_start_timestamp: u64,
95 pub end_of_epoch_info: Option<EndOfEpochInfo>,
97}
98
99#[serde_as]
100#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
101#[serde(rename_all = "camelCase")]
102pub struct EndOfEpochInfo {
103 #[schemars(with = "BigInt<u64>")]
104 #[serde_as(as = "BigInt<u64>")]
105 pub last_checkpoint_id: CheckpointSequenceNumber,
106 #[schemars(with = "BigInt<u64>")]
107 #[serde_as(as = "BigInt<u64>")]
108 pub epoch_end_timestamp: u64,
109 #[schemars(with = "BigInt<u64>")]
111 #[serde_as(as = "BigInt<u64>")]
112 pub protocol_version: u64,
113 #[schemars(with = "BigInt<u64>")]
114 #[serde_as(as = "BigInt<u64>")]
115 pub reference_gas_price: u64,
116 #[schemars(with = "BigInt<u64>")]
117 #[serde_as(as = "BigInt<u64>")]
118 pub total_stake: u64,
119 #[schemars(with = "BigInt<u64>")]
120 #[serde_as(as = "BigInt<u64>")]
121 pub storage_charge: u64,
122 #[schemars(with = "BigInt<u64>")]
123 #[serde_as(as = "BigInt<u64>")]
124 pub storage_rebate: u64,
125 #[schemars(with = "BigInt<u64>")]
126 #[serde_as(as = "BigInt<u64>")]
127 pub storage_fund_balance: u64,
128 #[schemars(with = "BigInt<u64>")]
129 #[serde_as(as = "BigInt<u64>")]
130 pub total_gas_fees: u64,
131 #[schemars(with = "BigInt<u64>")]
132 #[serde_as(as = "BigInt<u64>")]
133 pub total_stake_rewards_distributed: u64,
134 #[schemars(with = "BigInt<u64>")]
135 #[serde_as(as = "BigInt<u64>")]
136 pub burnt_tokens_amount: u64,
137 #[schemars(with = "BigInt<u64>")]
138 #[serde_as(as = "BigInt<u64>")]
139 pub minted_tokens_amount: u64,
140}
141
142#[serde_as]
143#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
144#[serde(rename_all = "camelCase")]
145pub struct NetworkMetrics {
146 pub current_tps: f64,
148 pub tps_30_days: f64,
150 #[schemars(with = "BigInt<u64>")]
152 #[serde_as(as = "BigInt<u64>")]
153 pub total_packages: u64,
154 #[schemars(with = "BigInt<u64>")]
156 #[serde_as(as = "BigInt<u64>")]
157 pub total_addresses: u64,
158 #[schemars(with = "BigInt<u64>")]
160 #[serde_as(as = "BigInt<u64>")]
161 pub total_objects: u64,
162 #[schemars(with = "BigInt<u64>")]
164 #[serde_as(as = "BigInt<u64>")]
165 pub current_epoch: u64,
166 #[schemars(with = "BigInt<u64>")]
168 #[serde_as(as = "BigInt<u64>")]
169 pub current_checkpoint: u64,
170}
171
172#[serde_as]
173#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
174#[serde(rename_all = "camelCase")]
175pub struct MoveCallMetrics {
176 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
178 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
179 pub rank_3_days: Vec<(MoveFunctionName, usize)>,
180 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
182 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
183 pub rank_7_days: Vec<(MoveFunctionName, usize)>,
184 #[schemars(with = "Vec<(MoveFunctionName, BigInt<usize>)>")]
186 #[serde_as(as = "Vec<(_, BigInt<usize>)>")]
187 pub rank_30_days: Vec<(MoveFunctionName, usize)>,
188}
189
190#[serde_as]
192#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
193#[serde(rename_all = "camelCase")]
194pub struct AddressMetrics {
195 pub checkpoint: u64,
197 pub epoch: u64,
199 pub timestamp_ms: u64,
201 pub cumulative_addresses: u64,
203 pub cumulative_active_addresses: u64,
205 pub daily_active_addresses: u64,
207}
208
209#[serde_as]
211#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
212#[serde(rename_all = "camelCase")]
213pub struct ParticipationMetrics {
214 pub total_addresses: u64,
216}