sui_rpc_api/proto/rpc/v2beta2/
system_state.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use super::MoveTable;
use super::StakeSubsidy;
use super::StakingPool;
use super::StorageFund;
use super::SystemParameters;
use super::SystemState;
use super::Validator;
use super::ValidatorReportRecord;
use super::ValidatorSet;

impl From<sui_types::sui_system_state::SuiSystemState> for SystemState {
    fn from(value: sui_types::sui_system_state::SuiSystemState) -> Self {
        match value {
            sui_types::sui_system_state::SuiSystemState::V1(v1) => v1.into(),
            sui_types::sui_system_state::SuiSystemState::V2(v2) => v2.into(),

            #[allow(unreachable_patterns)]
            _ => Self::default(),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1>
    for SystemState
{
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1 {
            epoch,
            protocol_version,
            system_state_version,
            validators,
            storage_fund,
            parameters,
            reference_gas_price,
            validator_report_records,
            stake_subsidy,
            safe_mode,
            safe_mode_storage_rewards,
            safe_mode_computation_rewards,
            safe_mode_storage_rebates,
            safe_mode_non_refundable_storage_fee,
            epoch_start_timestamp_ms,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::SuiSystemStateInnerV1,
    ) -> Self {
        let validator_report_records = validator_report_records
            .contents
            .into_iter()
            .map(|entry| ValidatorReportRecord {
                reported: Some(entry.key.to_string()),
                reporters: entry
                    .value
                    .contents
                    .iter()
                    .map(ToString::to_string)
                    .collect(),
            })
            .collect();

        Self {
            version: Some(system_state_version),
            epoch: Some(epoch),
            protocol_version: Some(protocol_version),
            validators: Some(validators.into()),
            storage_fund: Some(storage_fund.into()),
            parameters: Some(parameters.into()),
            reference_gas_price: Some(reference_gas_price),
            validator_report_records,
            stake_subsidy: Some(stake_subsidy.into()),
            safe_mode: Some(safe_mode),
            safe_mode_storage_rewards: Some(safe_mode_storage_rewards.value()),
            safe_mode_computation_rewards: Some(safe_mode_computation_rewards.value()),
            safe_mode_storage_rebates: Some(safe_mode_storage_rebates),
            safe_mode_non_refundable_storage_fee: Some(safe_mode_non_refundable_storage_fee),
            epoch_start_timestamp_ms: Some(epoch_start_timestamp_ms),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2>
    for SystemState
{
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2 {
            epoch,
            protocol_version,
            system_state_version,
            validators,
            storage_fund,
            parameters,
            reference_gas_price,
            validator_report_records,
            stake_subsidy,
            safe_mode,
            safe_mode_storage_rewards,
            safe_mode_computation_rewards,
            safe_mode_storage_rebates,
            safe_mode_non_refundable_storage_fee,
            epoch_start_timestamp_ms,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v2::SuiSystemStateInnerV2,
    ) -> Self {
        let validator_report_records = validator_report_records
            .contents
            .into_iter()
            .map(|entry| ValidatorReportRecord {
                reported: Some(entry.key.to_string()),
                reporters: entry
                    .value
                    .contents
                    .iter()
                    .map(ToString::to_string)
                    .collect(),
            })
            .collect();

        Self {
            version: Some(system_state_version),
            epoch: Some(epoch),
            protocol_version: Some(protocol_version),
            validators: Some(validators.into()),
            storage_fund: Some(storage_fund.into()),
            parameters: Some(parameters.into()),
            reference_gas_price: Some(reference_gas_price),
            validator_report_records,
            stake_subsidy: Some(stake_subsidy.into()),
            safe_mode: Some(safe_mode),
            safe_mode_storage_rewards: Some(safe_mode_storage_rewards.value()),
            safe_mode_computation_rewards: Some(safe_mode_computation_rewards.value()),
            safe_mode_storage_rebates: Some(safe_mode_storage_rebates),
            safe_mode_non_refundable_storage_fee: Some(safe_mode_non_refundable_storage_fee),
            epoch_start_timestamp_ms: Some(epoch_start_timestamp_ms),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::collection_types::Bag> for MoveTable {
    fn from(
        sui_types::collection_types::Bag { id, size }: sui_types::collection_types::Bag,
    ) -> Self {
        Self {
            id: Some(id.id.bytes.to_canonical_string(true)),
            size: Some(size),
        }
    }
}

impl From<sui_types::collection_types::Table> for MoveTable {
    fn from(
        sui_types::collection_types::Table { id, size }: sui_types::collection_types::Table,
    ) -> Self {
        Self {
            id: Some(id.to_canonical_string(true)),
            size: Some(size),
        }
    }
}

impl From<sui_types::collection_types::TableVec> for MoveTable {
    fn from(value: sui_types::collection_types::TableVec) -> Self {
        value.contents.into()
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1> for StakeSubsidy {
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1 {
            balance,
            distribution_counter,
            current_distribution_amount,
            stake_subsidy_period_length,
            stake_subsidy_decrease_rate,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::StakeSubsidyV1,
    ) -> Self {
        Self {
            balance: Some(balance.value()),
            distribution_counter: Some(distribution_counter),
            current_distribution_amount: Some(current_distribution_amount),
            stake_subsidy_period_length: Some(stake_subsidy_period_length),
            stake_subsidy_decrease_rate: Some(stake_subsidy_decrease_rate.into()),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::SystemParametersV1>
    for SystemParameters
{
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::SystemParametersV1 {
            epoch_duration_ms,
            stake_subsidy_start_epoch,
            max_validator_count,
            min_validator_joining_stake,
            validator_low_stake_threshold,
            validator_very_low_stake_threshold,
            validator_low_stake_grace_period,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::SystemParametersV1,
    ) -> Self {
        Self {
            epoch_duration_ms: Some(epoch_duration_ms),
            stake_subsidy_start_epoch: Some(stake_subsidy_start_epoch),
            min_validator_count: None,
            max_validator_count: Some(max_validator_count),
            min_validator_joining_stake: Some(min_validator_joining_stake),
            validator_low_stake_threshold: Some(validator_low_stake_threshold),
            validator_very_low_stake_threshold: Some(validator_very_low_stake_threshold),
            validator_low_stake_grace_period: Some(validator_low_stake_grace_period),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v2::SystemParametersV2>
    for SystemParameters
{
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v2::SystemParametersV2 {
            epoch_duration_ms,
            stake_subsidy_start_epoch,
            min_validator_count,
            max_validator_count,
            min_validator_joining_stake,
            validator_low_stake_threshold,
            validator_very_low_stake_threshold,
            validator_low_stake_grace_period,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v2::SystemParametersV2,
    ) -> Self {
        Self {
            epoch_duration_ms: Some(epoch_duration_ms),
            stake_subsidy_start_epoch: Some(stake_subsidy_start_epoch),
            min_validator_count: Some(min_validator_count),
            max_validator_count: Some(max_validator_count),
            min_validator_joining_stake: Some(min_validator_joining_stake),
            validator_low_stake_threshold: Some(validator_low_stake_threshold),
            validator_very_low_stake_threshold: Some(validator_very_low_stake_threshold),
            validator_low_stake_grace_period: Some(validator_low_stake_grace_period),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::StorageFundV1> for StorageFund {
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::StorageFundV1 {
            total_object_storage_rebates,
            non_refundable_balance,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::StorageFundV1,
    ) -> Self {
        Self {
            total_object_storage_rebates: Some(total_object_storage_rebates.value()),
            non_refundable_balance: Some(non_refundable_balance.value()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1> for ValidatorSet {
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1 {
            total_stake,
            active_validators,
            pending_active_validators,
            pending_removals,
            staking_pool_mappings,
            inactive_validators,
            validator_candidates,
            at_risk_validators,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorSetV1,
    ) -> Self {
        let at_risk_validators = at_risk_validators
            .contents
            .into_iter()
            .map(|entry| (entry.key.to_string(), entry.value))
            .collect();
        Self {
            total_stake: Some(total_stake),
            active_validators: active_validators.into_iter().map(Into::into).collect(),
            pending_active_validators: Some(pending_active_validators.into()),
            pending_removals,
            staking_pool_mappings: Some(staking_pool_mappings.into()),
            inactive_validators: Some(inactive_validators.into()),
            validator_candidates: Some(validator_candidates.into()),
            at_risk_validators,
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::StakingPoolV1> for StakingPool {
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::StakingPoolV1 {
            id,
            activation_epoch,
            deactivation_epoch,
            sui_balance,
            rewards_pool,
            pool_token_balance,
            exchange_rates,
            pending_stake,
            pending_total_sui_withdraw,
            pending_pool_token_withdraw,
            extra_fields,
        }: sui_types::sui_system_state::sui_system_state_inner_v1::StakingPoolV1,
    ) -> Self {
        Self {
            id: Some(id.to_canonical_string(true)),
            activation_epoch,
            deactivation_epoch,
            sui_balance: Some(sui_balance),
            rewards_pool: Some(rewards_pool.value()),
            pool_token_balance: Some(pool_token_balance),
            exchange_rates: Some(exchange_rates.into()),
            pending_stake: Some(pending_stake),
            pending_total_sui_withdraw: Some(pending_total_sui_withdraw),
            pending_pool_token_withdraw: Some(pending_pool_token_withdraw),
            extra_fields: Some(extra_fields.into()),
        }
    }
}

impl From<sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorV1> for Validator {
    fn from(
        sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorV1 {
            metadata:
                sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorMetadataV1 {
                    sui_address,
                    protocol_pubkey_bytes,
                    network_pubkey_bytes,
                    worker_pubkey_bytes,
                    proof_of_possession_bytes,
                    name,
                    description,
                    image_url,
                    project_url,
                    net_address,
                    p2p_address,
                    primary_address,
                    worker_address,
                    next_epoch_protocol_pubkey_bytes,
                    next_epoch_proof_of_possession,
                    next_epoch_network_pubkey_bytes,
                    next_epoch_worker_pubkey_bytes,
                    next_epoch_net_address,
                    next_epoch_p2p_address,
                    next_epoch_primary_address,
                    next_epoch_worker_address,
                    extra_fields: metadata_extra_fields,
                },
            voting_power,
            operation_cap_id,
            gas_price,
            staking_pool,
            commission_rate,
            next_epoch_stake,
            next_epoch_gas_price,
            next_epoch_commission_rate,
            extra_fields,
            ..
        }: sui_types::sui_system_state::sui_system_state_inner_v1::ValidatorV1,
    ) -> Self {
        Self {
            name: Some(name),
            address: Some(sui_address.to_string()),
            description: Some(description),
            image_url: Some(image_url),
            project_url: Some(project_url),
            protocol_public_key: Some(protocol_pubkey_bytes.into()),
            proof_of_possession: Some(proof_of_possession_bytes.into()),
            network_public_key: Some(network_pubkey_bytes.into()),
            worker_public_key: Some(worker_pubkey_bytes.into()),
            network_address: Some(net_address),
            p2p_address: Some(p2p_address),
            primary_address: Some(primary_address),
            worker_address: Some(worker_address),
            next_epoch_protocol_public_key: next_epoch_protocol_pubkey_bytes.map(Into::into),
            next_epoch_proof_of_possession: next_epoch_proof_of_possession.map(Into::into),
            next_epoch_network_public_key: next_epoch_network_pubkey_bytes.map(Into::into),
            next_epoch_worker_public_key: next_epoch_worker_pubkey_bytes.map(Into::into),
            next_epoch_network_address: next_epoch_net_address,
            next_epoch_p2p_address,
            next_epoch_primary_address,
            next_epoch_worker_address,
            metadata_extra_fields: Some(metadata_extra_fields.into()),
            voting_power: Some(voting_power),
            operation_cap_id: Some(operation_cap_id.bytes.to_canonical_string(true)),
            gas_price: Some(gas_price),
            staking_pool: Some(staking_pool.into()),
            commission_rate: Some(commission_rate),
            next_epoch_stake: Some(next_epoch_stake),
            next_epoch_gas_price: Some(next_epoch_gas_price),
            next_epoch_commission_rate: Some(next_epoch_commission_rate),
            extra_fields: Some(extra_fields.into()),
        }
    }
}