|
1 | 1 | // Copyright (c) Mysten Labs, Inc. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -use chrono::DateTime as ChronoDT; |
5 | | -use sui_types::types::CheckpointContentsDigest; |
6 | | -use sui_types::types::CheckpointDigest; |
| 4 | +use base64ct::Encoding; |
7 | 5 | use sui_types::types::CheckpointSummary; |
8 | | -use sui_types::types::GasCostSummary as NativeGasCostSummary; |
9 | 6 |
|
10 | 7 | use crate::error; |
11 | 8 | use crate::error::Error; |
12 | 9 | use crate::error::Kind; |
13 | 10 | use crate::query_types::schema; |
14 | 11 | use crate::query_types::Base64; |
15 | | -use crate::query_types::BigInt; |
16 | | -use crate::query_types::DateTime; |
17 | | -use crate::query_types::Epoch; |
18 | 12 | use crate::query_types::PageInfo; |
19 | 13 |
|
20 | 14 | // =========================================================================== |
@@ -84,99 +78,26 @@ pub struct CheckpointId { |
84 | 78 | #[derive(cynic::QueryFragment, Debug)] |
85 | 79 | #[cynic(schema = "rpc", graphql_type = "Checkpoint")] |
86 | 80 | pub struct Checkpoint { |
87 | | - pub epoch: Option<Epoch>, |
88 | | - pub digest: String, |
89 | | - pub network_total_transactions: Option<u64>, |
90 | | - pub previous_checkpoint_digest: Option<String>, |
91 | | - pub sequence_number: u64, |
92 | | - pub timestamp: DateTime, |
93 | | - pub validator_signatures: Base64, |
94 | | - pub rolling_gas_summary: Option<GasCostSummary>, |
95 | | -} |
96 | | - |
97 | | -#[derive(cynic::QueryFragment, Debug)] |
98 | | -#[cynic(schema = "rpc", graphql_type = "GasCostSummary")] |
99 | | -pub struct GasCostSummary { |
100 | | - pub computation_cost: Option<BigInt>, |
101 | | - pub non_refundable_storage_fee: Option<BigInt>, |
102 | | - pub storage_cost: Option<BigInt>, |
103 | | - pub storage_rebate: Option<BigInt>, |
| 81 | + pub bcs: Option<Base64>, |
104 | 82 | } |
105 | 83 |
|
106 | | -// TODO need bcs in GraphQL Checkpoint to avoid this conversion |
107 | 84 | impl TryInto<CheckpointSummary> for Checkpoint { |
108 | 85 | type Error = error::Error; |
109 | 86 |
|
110 | | - fn try_into(self) -> Result<CheckpointSummary, Self::Error> { |
111 | | - let epoch = self |
112 | | - .epoch |
113 | | - .ok_or_else(|| { |
114 | | - Error::from_error(Kind::Other, "Epoch is checkpoint summary is missing") |
115 | | - })? |
116 | | - .epoch_id; |
117 | | - let network_total_transactions = self.network_total_transactions.ok_or_else(|| { |
118 | | - Error::from_error( |
119 | | - Kind::Other, |
120 | | - "Network total transactions in checkpoint summary is missing", |
121 | | - ) |
122 | | - })?; |
123 | | - let sequence_number = self.sequence_number; |
124 | | - let timestamp_ms = ChronoDT::parse_from_rfc3339(&self.timestamp.0)? |
125 | | - .timestamp_millis() |
126 | | - .try_into()?; |
127 | | - let content_digest = CheckpointContentsDigest::from_base58(&self.digest)?; |
128 | | - let previous_digest = self |
129 | | - .previous_checkpoint_digest |
130 | | - .map(|d| CheckpointDigest::from_base58(&d)) |
| 87 | + fn try_into(self) -> Result<CheckpointSummary, Error> { |
| 88 | + let checkpoint = self |
| 89 | + .bcs |
| 90 | + .map(|x| base64ct::Base64::decode_vec(&x.0)) |
| 91 | + .transpose()? |
| 92 | + .map(|bcs| { |
| 93 | + bcs::from_bytes::<CheckpointSummary>(&bcs).map_err(|e| { |
| 94 | + Error::from_error( |
| 95 | + Kind::Other, |
| 96 | + format!("Failed to deserialize checkpoint summary: {}", e), |
| 97 | + ) |
| 98 | + }) |
| 99 | + }) |
131 | 100 | .transpose()?; |
132 | | - let epoch_rolling_gas_cost_summary = self |
133 | | - .rolling_gas_summary |
134 | | - .ok_or_else(|| { |
135 | | - Error::from_error( |
136 | | - Kind::Other, |
137 | | - "Gas cost summary in checkpoint summary is missing", |
138 | | - ) |
139 | | - })? |
140 | | - .try_into()?; |
141 | | - Ok(CheckpointSummary { |
142 | | - epoch, |
143 | | - sequence_number, |
144 | | - network_total_transactions, |
145 | | - timestamp_ms, |
146 | | - content_digest, |
147 | | - previous_digest, |
148 | | - epoch_rolling_gas_cost_summary, |
149 | | - checkpoint_commitments: vec![], |
150 | | - end_of_epoch_data: None, |
151 | | - version_specific_data: vec![], |
152 | | - }) |
153 | | - } |
154 | | -} |
155 | | - |
156 | | -impl TryInto<NativeGasCostSummary> for GasCostSummary { |
157 | | - type Error = error::Error; |
158 | | - fn try_into(self) -> Result<NativeGasCostSummary, Self::Error> { |
159 | | - let computation_cost = self |
160 | | - .computation_cost |
161 | | - .ok_or_else(|| Error::from_error(Kind::Other, "Computation cost is missing"))? |
162 | | - .try_into()?; |
163 | | - let non_refundable_storage_fee = self |
164 | | - .non_refundable_storage_fee |
165 | | - .ok_or_else(|| Error::from_error(Kind::Other, "Non-refundable storage fee is missing"))? |
166 | | - .try_into()?; |
167 | | - let storage_cost = self |
168 | | - .storage_cost |
169 | | - .ok_or_else(|| Error::from_error(Kind::Other, "Storage cost is missing"))? |
170 | | - .try_into()?; |
171 | | - let storage_rebate = self |
172 | | - .storage_rebate |
173 | | - .ok_or_else(|| Error::from_error(Kind::Other, "Storage rebate is missing"))? |
174 | | - .try_into()?; |
175 | | - Ok(NativeGasCostSummary { |
176 | | - computation_cost, |
177 | | - non_refundable_storage_fee, |
178 | | - storage_cost, |
179 | | - storage_rebate, |
180 | | - }) |
| 101 | + checkpoint.ok_or_else(|| Error::from_error(Kind::Other, "Checkpoint summary is missing")) |
181 | 102 | } |
182 | 103 | } |
0 commit comments