sui_json_rpc_types/
sui_extended.rs1use std::collections::BTreeMap;
5
6use fastcrypto::traits::ToFromBytes;
7use move_core_types::identifier::Identifier;
8use schemars::JsonSchema;
9use serde::Deserialize;
10use serde::Serialize;
11use serde_with::DisplayFromStr;
12use serde_with::serde_as;
13
14use sui_types::base_types::AuthorityName;
15use sui_types::base_types::{EpochId, ObjectID};
16use sui_types::committee::Committee;
17use sui_types::messages_checkpoint::CheckpointSequenceNumber;
18use sui_types::sui_serde::BigInt;
19use sui_types::sui_system_state::sui_system_state_summary::SuiValidatorSummary;
20
21use crate::Page;
22
23pub type EpochPage = Page<EpochInfo, 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<SuiValidatorSummary>,
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>")]
44 #[serde_as(as = "BigInt<u64>")]
45 pub epoch_start_timestamp: u64,
46 pub end_of_epoch_info: Option<EndOfEpochInfo>,
47 pub reference_gas_price: Option<u64>,
48}
49
50impl EpochInfo {
51 pub fn committee(&self) -> Result<Committee, fastcrypto::error::FastCryptoError> {
52 let mut voting_rights = BTreeMap::new();
53 for validator in &self.validators {
54 let name = AuthorityName::from_bytes(&validator.protocol_pubkey_bytes)?;
55 voting_rights.insert(name, validator.voting_power);
56 }
57 Ok(Committee::new(self.epoch, voting_rights))
58 }
59}
60
61#[serde_as]
62#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
63#[serde(rename_all = "camelCase")]
64pub struct EndOfEpochInfo {
65 #[schemars(with = "BigInt<u64>")]
66 #[serde_as(as = "BigInt<u64>")]
67 pub last_checkpoint_id: CheckpointSequenceNumber,
68 #[schemars(with = "BigInt<u64>")]
69 #[serde_as(as = "BigInt<u64>")]
70 pub epoch_end_timestamp: u64,
71 #[schemars(with = "BigInt<u64>")]
73 #[serde_as(as = "BigInt<u64>")]
74 pub protocol_version: u64,
75 #[schemars(with = "BigInt<u64>")]
76 #[serde_as(as = "BigInt<u64>")]
77 pub reference_gas_price: u64,
78 #[schemars(with = "BigInt<u64>")]
79 #[serde_as(as = "BigInt<u64>")]
80 pub total_stake: u64,
81 #[schemars(with = "BigInt<u64>")]
82 #[serde_as(as = "BigInt<u64>")]
83 pub storage_fund_reinvestment: u64,
84 #[schemars(with = "BigInt<u64>")]
85 #[serde_as(as = "BigInt<u64>")]
86 pub storage_charge: u64,
87 #[schemars(with = "BigInt<u64>")]
88 #[serde_as(as = "BigInt<u64>")]
89 pub storage_rebate: u64,
90 #[schemars(with = "BigInt<u64>")]
91 #[serde_as(as = "BigInt<u64>")]
92 pub storage_fund_balance: u64,
93 #[schemars(with = "BigInt<u64>")]
94 #[serde_as(as = "BigInt<u64>")]
95 pub stake_subsidy_amount: u64,
96 #[schemars(with = "BigInt<u64>")]
97 #[serde_as(as = "BigInt<u64>")]
98 pub total_gas_fees: u64,
99 #[schemars(with = "BigInt<u64>")]
100 #[serde_as(as = "BigInt<u64>")]
101 pub total_stake_rewards_distributed: u64,
102 #[schemars(with = "BigInt<u64>")]
103 #[serde_as(as = "BigInt<u64>")]
104 pub leftover_storage_fund_inflow: u64,
105}
106
107#[serde_as]
108#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
109#[serde(rename_all = "camelCase")]
110pub struct MoveFunctionName {
111 pub package: ObjectID,
112 #[schemars(with = "String")]
113 #[serde_as(as = "DisplayFromStr")]
114 pub module: Identifier,
115 #[schemars(with = "String")]
116 #[serde_as(as = "DisplayFromStr")]
117 pub function: Identifier,
118}