From 0fa27f654e4786b264220fc06d7902e176ccd694 Mon Sep 17 00:00:00 2001 From: Valerii Reutov Date: Tue, 5 Nov 2024 16:40:25 +0200 Subject: [PATCH] feat(iota-framework): store system display objects in the system state --- .../iota-system/sources/iota_system.move | 37 ++++++++++++++-- .../sources/iota_system_display.move | 40 +++++++++++++++++- .../sources/iota_system_state_inner.move | 25 +++++++++++ .../packages_compiled/iota-system | Bin 42939 -> 43793 bytes crates/iota-framework/published_api.txt | 36 ++++++++++++++-- 5 files changed, 129 insertions(+), 9 deletions(-) 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 4030df4d729ca96768670124f066bc0cae74ae8b..6413665c0ac2ed210acfb3f72c230d2aef0c5231 100644 GIT binary patch delta 5385 zcma)AS#TUz6}|8FI{mt5x?3}&8ELfHvSe)|S(c@?yh*X-Mc(CAUZUNWyvdOjCw3Ah zcAPzggib;T5cUxEfLX#;1$^)U6ciuu!4E|he=OmLD)^zew@0!yB1JJ(bKbk>-TUUg z?Y{fw2fxObe~0fRCJJBg|8(xpQU?HAKqq$2C~t^Q=<0Wke(j&en}+dP;#<|`&)dfI zFXb;-ueQ(Gw>y61IzQ>lC*JE*VGygZ8rR@Dybq7!349bkfKLj1O5k?|zANAwT!$|T z_>zFH32{t(Pk^HW==8M}5MV?2!HJPVBUNE7DgcwJ1~9D?Oc(@H4ChROs|;sj1oI4I zmIN5L31*x)!2Jp0o)(OwF2OT`vBJ~PP@&c@_D0NxSRwE*7`m307{xp8ClDu7K~>tz^OT@R41Tm!JaAr2yYm`5jS zj_~Njs-rwQG2F2Zu%%rSfJ0|;gb$u=C;X1MpM@Wa(=7c+XjCX&5A+lE_qP`WsI5bq zP_)%!InWMH$3eR-&ga0`bD4UwPR(n=mUHX7z;4(*h_q~NS{oNV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3VUzX-n|W^us%7>v)MnXqwhf?OE)1f< z0^MV{1>P_HXwFeqVT2X>)fJq0$}Sa(h!!oJJ3*Ax7NKMx$^cXCNQEvxi|MTO*xlwj zNtZxDmz*f=OuBY)jf%V~?=+OBoZ_(W^cPW&ix?{xN~_UjWo8UkqF3&)5#!~;dQ6lH z8_+Kowqvqf*o>)iVJ)Voh0@dqQYNb?cNxY^xiE&6<-!P7vGDm|)3|NI>bcSytSJxM zhPAVVF&dOnted5fum$VOg>^_<=*}Q5MA|MO=#cT6z4_QgsnxHc*SFZ=WuOq;cqUuw z#%9t(r`9~SaG4GquN7O_o$m%fsb2U+%@%x<9HMkD=$7DWK3`Y`rR4CKntn|mw#_ux z>~&%8P6v9CE1(*hU?u!DIh}?ltAqW1>7U9>R;Dy)qn%P3Yt(*KTeaA@@}4k%jpO#q zN+TGkp@mV<1tm&bn1c6(q9Ukh(m6?Kl#U-^QVT@N{Y={=swVv}1N|n@(J&Rmq;mm8 z1XMCCQ?<+vDj`h~{Zi7&JwmP~S*X$@bl`ep@c7v?rzS20rCUwG$FF#%acEk2_tk5` d|DGIg;$K7xuTZ*l76ApDJni8flnz^g@P7|Z)LH-l 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