diff --git a/crates/iota-framework/packages/iota-system/sources/iota_system.move b/crates/iota-framework/packages/iota-system/sources/iota_system.move index dc8801f5be5..813fbc0c81a 100644 --- a/crates/iota-framework/packages/iota-system/sources/iota_system.move +++ b/crates/iota-framework/packages/iota-system/sources/iota_system.move @@ -500,6 +500,39 @@ module iota_system::iota_system { self.active_validator_addresses() } + /// Returns the IOTA system admin capability reference. + public(package) fun load_iota_system_admin_cap(self: &mut IotaSystemState): &IotaSystemAdminCap { + self.load_system_state().iota_system_admin_cap() + } + + /// Add an object with the specified key to the extra fields collection. + public(package) fun add_extra_field( + wrapper: &mut IotaSystemState, + key: K, + value: V, + ) { + let self = load_system_state_mut(wrapper); + self.add_extra_field(key, value); + } + + /// Immutable borrows the value associated with the key in the extra fields. + public(package) fun borrow_extra_field( + wrapper: &mut IotaSystemState, + key: K, + ): &V { + let self = load_system_state(wrapper); + self.borrow_extra_field(key) + } + + /// Mutable borrows the value associated with the key in the extra fields. + public(package) fun borrow_extra_field_mut( + wrapper: &mut IotaSystemState, + key: K, + ): &mut V { + let self = load_system_state_mut(wrapper); + self.borrow_extra_field_mut(key) + } + #[allow(unused_function)] /// This function should be called at the end of an epoch, and advances the system to the next epoch. /// It does the following things: @@ -560,10 +593,6 @@ module iota_system::iota_system { inner } - public(package) fun load_iota_system_admin_cap(self: &mut IotaSystemState): &IotaSystemAdminCap { - self.load_system_state().iota_system_admin_cap() - } - #[allow(unused_function)] /// Returns the voting power of the active validators, values are voting power in the scale of 10000. fun validator_voting_powers(wrapper: &mut IotaSystemState): VecMap { diff --git a/crates/iota-framework/packages/iota-system/sources/iota_system_display.move b/crates/iota-framework/packages/iota-system/sources/iota_system_display.move index bc1249d6388..a751e0ec855 100644 --- a/crates/iota-framework/packages/iota-system/sources/iota_system_display.move +++ b/crates/iota-framework/packages/iota-system/sources/iota_system_display.move @@ -3,7 +3,7 @@ module iota_system::iota_system_display { - use std::string::String; + use std::string::{Self, String}; use iota::display::{Self, Display}; @@ -21,7 +21,7 @@ module iota_system::iota_system_display { display::system_new(sys_admin_cap, ctx) } - /// Create a new Display object with a set of fields using `IotaSystemAdminCap`. + /// Create a new `Display` object with a set of fields using `IotaSystemAdminCap`. public(package) fun system_new_with_fields( iota_system: &mut IotaSystemState, fields: vector, @@ -34,4 +34,40 @@ module iota_system::iota_system_display { // Create a `Display` object with fields. display::system_new_with_fields(sys_admin_cap, fields, values, ctx) } + + /// Add a display object to the system state store. + public(package) fun add_display_object( + iota_system: &mut IotaSystemState, + display: Display + ) { + // Get a display object unique key. + let key = display_object_key(); + + // Store the display object. + iota_system.add_extra_field(key, display); + } + + /// Borrow an immutable display object from the system state store. + public(package) fun borrow_display_object(iota_system: &mut IotaSystemState): &Display { + // Get a display object unique key. + let key = display_object_key(); + + // Borrow the display object. + iota_system.borrow_extra_field(key) + } + + /// Borrow a mutable display object from the system state store. + public(package) fun borrow_display_object_mut(iota_system: &mut IotaSystemState): &mut Display { + // Get a display object unique key. + let key = display_object_key(); + + // Borrow the display object. + iota_system.borrow_extra_field_mut(key) + } + + /// Return a fully qualified type name with the original package IDs + /// that is used as a display object key. + fun display_object_key(): String { + string::from_ascii(std::type_name::get_with_original_ids().into_string()) + } } diff --git a/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move b/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move index 5e701a31961..4decabb15a3 100644 --- a/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move +++ b/crates/iota-framework/packages/iota-system/sources/iota_system_state_inner.move @@ -442,6 +442,31 @@ module iota_system::iota_system_state_inner { } } + /// Add an object with the specified key to the extra fields collection. + public(package) fun add_extra_field( + self: &mut IotaSystemStateV1, + key: K, + value: V, + ) { + self.extra_fields.add(key, value); + } + + /// Immutable borrows the value associated with the key in the extra fields. + public(package) fun borrow_extra_field( + self: &IotaSystemStateV1, + key: K, + ): &V { + self.extra_fields.borrow(key) + } + + /// Mutable borrows the value associated with the key in the extra fields. + public(package) fun borrow_extra_field_mut( + self: &mut IotaSystemStateV1, + key: K, + ): &mut V { + self.extra_fields.borrow_mut(key) + } + // ==== validator metadata management functions ==== /// Create a new `UnverifiedValidatorOperationCap`, transfer it to the diff --git a/crates/iota-framework/packages_compiled/iota-system b/crates/iota-framework/packages_compiled/iota-system index 4030df4d729..6413665c0ac 100644 Binary files a/crates/iota-framework/packages_compiled/iota-system and b/crates/iota-framework/packages_compiled/iota-system differ diff --git a/crates/iota-framework/published_api.txt b/crates/iota-framework/published_api.txt index b48aed22add..00caaee365a 100644 --- a/crates/iota-framework/published_api.txt +++ b/crates/iota-framework/published_api.txt @@ -673,6 +673,15 @@ report_validator_impl undo_report_validator_impl fun 0x3::iota_system_state_inner +add_extra_field + public(package) fun + 0x3::iota_system_state_inner +borrow_extra_field + public(package) fun + 0x3::iota_system_state_inner +borrow_extra_field_mut + public(package) fun + 0x3::iota_system_state_inner rotate_operation_cap public(package) fun 0x3::iota_system_state_inner @@ -889,6 +898,18 @@ pool_exchange_rates active_validator_addresses public fun 0x3::iota_system +load_iota_system_admin_cap + public(package) fun + 0x3::iota_system +add_extra_field + public(package) fun + 0x3::iota_system +borrow_extra_field + public(package) fun + 0x3::iota_system +borrow_extra_field_mut + public(package) fun + 0x3::iota_system advance_epoch fun 0x3::iota_system @@ -901,9 +922,6 @@ load_system_state_mut load_inner_maybe_upgrade fun 0x3::iota_system -load_iota_system_admin_cap - public(package) fun - 0x3::iota_system validator_voting_powers fun 0x3::iota_system @@ -1006,6 +1024,18 @@ system_new system_new_with_fields public(package) fun 0x3::iota_system_display +add_display_object + public(package) fun + 0x3::iota_system_display +borrow_display_object + public(package) fun + 0x3::iota_system_display +borrow_display_object_mut + public(package) fun + 0x3::iota_system_display +display_object_key + fun + 0x3::iota_system_display secp256k1_ecrecover public fun 0x2::ecdsa_k1