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        } = source;
18
19        if mask.contains(Self::EPOCH_FIELD.name) {
20            self.epoch = *epoch;
21        }
22
23        if mask.contains(Self::COMMITTEE_FIELD.name) {
24            self.committee = committee.to_owned();
25        }
26
27        if mask.contains(Self::SYSTEM_STATE_FIELD.name) {
28            self.system_state = system_state.to_owned();
29        }
30
31        if mask.contains(Self::FIRST_CHECKPOINT_FIELD.name) {
32            self.first_checkpoint = first_checkpoint.to_owned();
33        }
34
35        if mask.contains(Self::LAST_CHECKPOINT_FIELD.name) {
36            self.last_checkpoint = last_checkpoint.to_owned();
37        }
38
39        if mask.contains(Self::START_FIELD.name) {
40            self.start = start.to_owned();
41        }
42
43        if mask.contains(Self::END_FIELD.name) {
44            self.end = end.to_owned();
45        }
46
47        if mask.contains(Self::REFERENCE_GAS_PRICE_FIELD.name) {
48            self.reference_gas_price = reference_gas_price.to_owned();
49        }
50
51        if let Some(submask) = mask.subtree(Self::PROTOCOL_CONFIG_FIELD.name) {
52            self.protocol_config = protocol_config
53                .as_ref()
54                .map(|config| ProtocolConfig::merge_from(config, &submask));
55        }
56    }
57}
58
59impl Merge<&ProtocolConfig> for ProtocolConfig {
60    fn merge(&mut self, source: &ProtocolConfig, mask: &FieldMaskTree) {
61        let ProtocolConfig {
62            protocol_version,
63            feature_flags,
64            attributes,
65            configs,
66        } = source;
67
68        if mask.contains(Self::PROTOCOL_VERSION_FIELD.name) {
69            self.protocol_version = *protocol_version;
70        }
71
72        if mask.contains(Self::FEATURE_FLAGS_FIELD.name) {
73            self.feature_flags = feature_flags.to_owned();
74        }
75
76        if mask.contains(Self::ATTRIBUTES_FIELD.name) {
77            self.attributes = attributes.to_owned();
78        }
79
80        if mask.contains(Self::CONFIGS_FIELD.name) {
81            self.configs = configs.to_owned();
82        }
83    }
84}
85
86impl Merge<ProtocolConfig> for ProtocolConfig {
87    fn merge(&mut self, source: ProtocolConfig, mask: &FieldMaskTree) {
88        let ProtocolConfig {
89            protocol_version,
90            feature_flags,
91            attributes,
92            configs,
93        } = source;
94
95        if mask.contains(Self::PROTOCOL_VERSION_FIELD.name) {
96            self.protocol_version = protocol_version;
97        }
98
99        if mask.contains(Self::FEATURE_FLAGS_FIELD.name) {
100            self.feature_flags = feature_flags;
101        }
102
103        if mask.contains(Self::ATTRIBUTES_FIELD.name) {
104            self.attributes = attributes;
105        }
106
107        if mask.contains(Self::CONFIGS_FIELD.name) {
108            self.configs = configs;
109        }
110    }
111}