radix_engine/updates/
dugong.rs1use super::*;
2use crate::{internal_prelude::*, system::system_callback::SystemBoot};
3
4#[derive(Clone, ScryptoSbor)]
5pub struct DugongSettings {
6 pub native_entity_metadata_updates: UpdateSetting<NoSettings>,
7 pub system_logic_updates: UpdateSetting<NoSettings>,
8}
9
10impl UpdateSettings for DugongSettings {
11 type UpdateGenerator = DugongGenerator;
12
13 fn protocol_version() -> ProtocolVersion {
14 ProtocolVersion::Dugong
15 }
16
17 fn all_enabled_as_default_for_network(_network: &NetworkDefinition) -> Self {
23 Self::all_disabled()
24 }
25
26 fn all_disabled() -> Self {
27 Self {
28 native_entity_metadata_updates: UpdateSetting::Disabled,
29 system_logic_updates: UpdateSetting::Disabled,
30 }
31 }
32
33 fn create_generator(&self) -> Self::UpdateGenerator {
34 Self::UpdateGenerator {
35 settings: self.clone(),
36 }
37 }
38}
39
40pub struct DugongGenerator {
41 settings: DugongSettings,
42}
43
44impl ProtocolUpdateGenerator for DugongGenerator {
45 fn batch_groups(&self) -> Vec<Box<dyn ProtocolUpdateBatchGroupGenerator<'_> + '_>> {
46 vec![FixedBatchGroupGenerator::named("principal")
47 .add_batch("primary", |store| {
48 generate_main_batch(store, &self.settings)
49 })
50 .build()]
51 }
52}
53
54#[deny(unused_variables)]
55fn generate_main_batch(
56 store: &dyn SubstateDatabase,
57 DugongSettings {
58 native_entity_metadata_updates,
59 system_logic_updates,
60 }: &DugongSettings,
61) -> ProtocolUpdateBatch {
62 let mut batch = ProtocolUpdateBatch::empty();
63
64 if let UpdateSetting::Enabled(NoSettings) = &native_entity_metadata_updates {
65 batch.mut_add_flash(
66 "dugong-native-entity-metadata-updates",
67 generate_dugong_native_metadata_updates(),
68 );
69 }
70
71 if let UpdateSetting::Enabled(NoSettings) = &system_logic_updates {
72 batch.mut_add_flash(
73 "dugong-system-logic-updates",
74 generate_system_logic_v4_updates(store),
75 );
76 }
77
78 batch
79}
80
81fn generate_dugong_native_metadata_updates() -> StateUpdates {
82 let mut metadata_updates: IndexMap<NodeId, MetadataInit> = Default::default();
83 metadata_updates.insert(
84 METADATA_MODULE_PACKAGE.into_node_id(),
85 metadata_init! {
86 "name" => "Metadata Module Package", locked;
87 "description" => "A native package that defines the logic of the metadata module which is attached to global objects. The metadata module allows for setting and reading metadata.", locked;
88 },
89 );
90 metadata_updates.insert(
91 ROLE_ASSIGNMENT_MODULE_PACKAGE.into_node_id(),
92 metadata_init! {
93 "name" => "Role Assignment Module Package", locked;
94 "description" => "A native package that defines the logic of the role assignments module which is attached to global objects. The role assignments module is used by the system to set and resolve the access roles for entity roles.", locked;
95 },
96 );
97 metadata_updates.insert(
98 ROYALTY_MODULE_PACKAGE.into_node_id(),
99 metadata_init! {
100 "name" => "Royalty Module Package", locked;
101 "description" => "A native package that defines the logic of the royalty module which is optionally attached to global components if they enable royalties. The royalties module is used to configure and claim component royalties.", locked;
102 },
103 );
104
105 let mut state_updates = StateUpdates::empty();
106 for (node_id, metadata_updates) in metadata_updates.into_iter() {
107 let node_updates = create_metadata_substates(metadata_updates).into_node_state_updates();
108 state_updates.mut_add_node_updates(node_id, node_updates);
109 }
110
111 state_updates
112}
113
114fn generate_system_logic_v4_updates(store: &dyn SubstateDatabase) -> StateUpdates {
115 let existing_system_boot: SystemBoot = store.get_existing_substate(
116 TRANSACTION_TRACKER,
117 BOOT_LOADER_PARTITION,
118 BootLoaderField::SystemBoot,
119 );
120
121 StateUpdates::empty().set_substate(
122 TRANSACTION_TRACKER,
123 BOOT_LOADER_PARTITION,
124 BootLoaderField::SystemBoot,
125 SystemBoot::dugong_for_previous_parameters(existing_system_boot.into_parameters()),
126 )
127}