iota_json_rpc_types/
iota_checkpoint.rs1use fastcrypto::encoding::Base64;
6use iota_types::{
7 base_types::TransactionDigest,
8 committee::EpochId,
9 crypto::AggregateAuthoritySignature,
10 digests::CheckpointDigest,
11 gas::GasCostSummary,
12 iota_serde::BigInt,
13 message_envelope::Message,
14 messages_checkpoint::{
15 CheckpointCommitment, CheckpointContents, CheckpointSequenceNumber, CheckpointSummary,
16 CheckpointTimestamp, EndOfEpochData,
17 },
18};
19use schemars::JsonSchema;
20use serde::{Deserialize, Serialize};
21use serde_with::serde_as;
22
23use crate::Page;
24pub type CheckpointPage = Page<Checkpoint, BigInt<u64>>;
25
26#[serde_as]
27#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
28#[serde(rename_all = "camelCase")]
29pub struct Checkpoint {
30 #[schemars(with = "BigInt<u64>")]
32 #[serde_as(as = "BigInt<u64>")]
33 pub epoch: EpochId,
34 #[schemars(with = "BigInt<u64>")]
36 #[serde_as(as = "BigInt<u64>")]
37 pub sequence_number: CheckpointSequenceNumber,
38 pub digest: CheckpointDigest,
40 #[schemars(with = "BigInt<u64>")]
43 #[serde_as(as = "BigInt<u64>")]
44 pub network_total_transactions: u64,
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub previous_digest: Option<CheckpointDigest>,
48 pub epoch_rolling_gas_cost_summary: GasCostSummary,
51 #[schemars(with = "BigInt<u64>")]
56 #[serde_as(as = "BigInt<u64>")]
57 pub timestamp_ms: CheckpointTimestamp,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 pub end_of_epoch_data: Option<EndOfEpochData>,
61 pub transactions: Vec<TransactionDigest>,
63
64 pub checkpoint_commitments: Vec<CheckpointCommitment>,
66 #[schemars(with = "Base64")]
68 pub validator_signature: AggregateAuthoritySignature,
70}
71
72impl
73 From<(
74 CheckpointSummary,
75 CheckpointContents,
76 AggregateAuthoritySignature,
77 )> for Checkpoint
78{
79 fn from(
80 (summary, contents, signature): (
81 CheckpointSummary,
82 CheckpointContents,
83 AggregateAuthoritySignature,
84 ),
85 ) -> Self {
86 let digest = summary.digest();
87 let CheckpointSummary {
88 epoch,
89 sequence_number,
90 network_total_transactions,
91 previous_digest,
92 epoch_rolling_gas_cost_summary,
93 timestamp_ms,
94 end_of_epoch_data,
95 ..
96 } = summary;
97
98 Checkpoint {
99 epoch,
100 sequence_number,
101 digest,
102 network_total_transactions,
103 previous_digest,
104 epoch_rolling_gas_cost_summary,
105 timestamp_ms,
106 end_of_epoch_data,
107 transactions: contents.iter().map(|digest| digest.transaction).collect(),
108 checkpoint_commitments: Default::default(),
112 validator_signature: signature,
113 }
114 }
115}
116
117#[serde_as]
118#[derive(Clone, Copy, Debug, JsonSchema, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum CheckpointId {
121 SequenceNumber(
122 #[schemars(with = "BigInt<u64>")]
123 #[serde_as(as = "BigInt<u64>")]
124 CheckpointSequenceNumber,
125 ),
126 Digest(CheckpointDigest),
127}
128
129impl From<CheckpointSequenceNumber> for CheckpointId {
130 fn from(seq: CheckpointSequenceNumber) -> Self {
131 Self::SequenceNumber(seq)
132 }
133}
134
135impl From<CheckpointDigest> for CheckpointId {
136 fn from(digest: CheckpointDigest) -> Self {
137 Self::Digest(digest)
138 }
139}