Skip to main content

sui_rpc/proto/sui/rpc/v2/
epoch.rs

1use super::*;
2use crate::field::FieldMaskTree;
3use crate::merge::Merge;
4
5impl Merge<&Epoch> for Epoch {
6    fn merge(&mut self, source: &Epoch, mask: &FieldMaskTree) {
7        let Epoch {
8            epoch,
9            committee,
10            system_state,
11            first_checkpoint,
12            last_checkpoint,
13            start,
14            end,
15            reference_gas_price,
16            protocol_config,
17            transaction_start_inclusive,
18            transaction_end_exclusive,
19            ended_in_safe_mode,
20            system_epoch_info,
21            epoch_commitments,
22        } = source;
23
24        if mask.contains(Self::EPOCH_FIELD.name) {
25            self.epoch = *epoch;
26        }
27
28        if mask.contains(Self::COMMITTEE_FIELD.name) {
29            self.committee = committee.to_owned();
30        }
31
32        if mask.contains(Self::SYSTEM_STATE_FIELD.name) {
33            self.system_state = system_state.to_owned();
34        }
35
36        if mask.contains(Self::FIRST_CHECKPOINT_FIELD.name) {
37            self.first_checkpoint = first_checkpoint.to_owned();
38        }
39
40        if mask.contains(Self::LAST_CHECKPOINT_FIELD.name) {
41            self.last_checkpoint = last_checkpoint.to_owned();
42        }
43
44        if mask.contains(Self::START_FIELD.name) {
45            self.start = start.to_owned();
46        }
47
48        if mask.contains(Self::END_FIELD.name) {
49            self.end = end.to_owned();
50        }
51
52        if mask.contains(Self::REFERENCE_GAS_PRICE_FIELD.name) {
53            self.reference_gas_price = reference_gas_price.to_owned();
54        }
55
56        if let Some(submask) = mask.subtree(Self::PROTOCOL_CONFIG_FIELD.name) {
57            self.protocol_config = protocol_config
58                .as_ref()
59                .map(|config| ProtocolConfig::merge_from(config, &submask));
60        }
61
62        if mask.contains(Self::TRANSACTION_START_INCLUSIVE_FIELD.name) {
63            self.transaction_start_inclusive = *transaction_start_inclusive;
64        }
65
66        if mask.contains(Self::TRANSACTION_END_EXCLUSIVE_FIELD.name) {
67            self.transaction_end_exclusive = *transaction_end_exclusive;
68        }
69
70        if mask.contains(Self::ENDED_IN_SAFE_MODE_FIELD.name) {
71            self.ended_in_safe_mode = *ended_in_safe_mode;
72        }
73
74        if mask.contains(Self::SYSTEM_EPOCH_INFO_FIELD.name) {
75            self.system_epoch_info = system_epoch_info.to_owned();
76        }
77
78        if mask.contains(Self::EPOCH_COMMITMENTS_FIELD.name) {
79            self.epoch_commitments = epoch_commitments.to_owned();
80        }
81    }
82}
83
84impl Merge<&ProtocolConfig> for ProtocolConfig {
85    fn merge(&mut self, source: &ProtocolConfig, mask: &FieldMaskTree) {
86        let ProtocolConfig {
87            protocol_version,
88            feature_flags,
89            attributes,
90            configs,
91        } = source;
92
93        if mask.contains(Self::PROTOCOL_VERSION_FIELD.name) {
94            self.protocol_version = *protocol_version;
95        }
96
97        if mask.contains(Self::FEATURE_FLAGS_FIELD.name) {
98            self.feature_flags = feature_flags.to_owned();
99        }
100
101        if mask.contains(Self::ATTRIBUTES_FIELD.name) {
102            self.attributes = attributes.to_owned();
103        }
104
105        if mask.contains(Self::CONFIGS_FIELD.name) {
106            self.configs = configs.to_owned();
107        }
108    }
109}
110
111impl Merge<ProtocolConfig> for ProtocolConfig {
112    fn merge(&mut self, source: ProtocolConfig, mask: &FieldMaskTree) {
113        let ProtocolConfig {
114            protocol_version,
115            feature_flags,
116            attributes,
117            configs,
118        } = source;
119
120        if mask.contains(Self::PROTOCOL_VERSION_FIELD.name) {
121            self.protocol_version = protocol_version;
122        }
123
124        if mask.contains(Self::FEATURE_FLAGS_FIELD.name) {
125            self.feature_flags = feature_flags;
126        }
127
128        if mask.contains(Self::ATTRIBUTES_FIELD.name) {
129            self.attributes = attributes;
130        }
131
132        if mask.contains(Self::CONFIGS_FIELD.name) {
133            self.configs = configs;
134        }
135    }
136}