From 04bda8f02f74b6d77671d7dc8e72324ccb2b82ff Mon Sep 17 00:00:00 2001 From: pscott <30843220+pscott@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:08:07 +0200 Subject: [PATCH] use correct syntax for no_update (#528) * use correct syntax for no_update * add NoUpdateString --- starknet/src/space/space.cairo | 49 ++++++++++--------- starknet/src/types.cairo | 1 + .../src/types/update_settings_calldata.cairo | 15 ++++++ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/starknet/src/space/space.cairo b/starknet/src/space/space.cairo index a1e20fe0..a4633cba 100644 --- a/starknet/src/space/space.cairo +++ b/starknet/src/space/space.cairo @@ -94,7 +94,7 @@ mod Space { types::{ UserAddress, Choice, FinalizationStatus, Strategy, IndexedStrategy, Proposal, PackedProposal, IndexedStrategyTrait, IndexedStrategyImpl, UpdateSettingsCalldata, - NoUpdateU32, NoUpdateStrategy, NoUpdateArray + NoUpdateTrait, NoUpdateString, }, utils::{ reinitializable::{Reinitializable}, ReinitializableImpl, bits::BitSetter, @@ -601,8 +601,7 @@ mod Space { let _min_voting_duration = input.min_voting_duration; let _max_voting_duration = input.max_voting_duration; - if NoUpdateU32::should_update(@_max_voting_duration) - && NoUpdateU32::should_update(@_min_voting_duration) { + if _max_voting_duration.should_update() && _min_voting_duration.should_update() { // Check that min and max voting durations are valid // We don't use the internal `_set_min_voting_duration` and `_set_max_voting_duration` functions because // it would revert when `_min_voting_duration > max_voting_duration` (when the new `_min` is @@ -628,7 +627,7 @@ mod Space { } ) ); - } else if NoUpdateU32::should_update(@_min_voting_duration) { + } else if _min_voting_duration.should_update() { _set_min_voting_duration(ref self, input.min_voting_duration); self .emit( @@ -638,7 +637,7 @@ mod Space { } ) ); - } else if NoUpdateU32::should_update(@_max_voting_duration) { + } else if _max_voting_duration.should_update() { _set_max_voting_duration(ref self, input.max_voting_duration); self .emit( @@ -650,7 +649,7 @@ mod Space { ); } - if NoUpdateU32::should_update(@input.voting_delay) { + if input.voting_delay.should_update() { _set_voting_delay(ref self, input.voting_delay); self @@ -661,20 +660,7 @@ mod Space { ); } - if NoUpdateArray::should_update((@input).metadata_URI) { - self - .emit( - Event::MetadataUriUpdated( - MetadataUriUpdated { metadata_URI: input.metadata_URI.span() } - ) - ); - } - - if NoUpdateArray::should_update((@input).dao_URI) { - self.emit(Event::DaoUriUpdated(DaoUriUpdated { dao_URI: input.dao_URI.span() })); - } - - if NoUpdateStrategy::should_update((@input).proposal_validation_strategy) { + if input.proposal_validation_strategy.should_update() { _set_proposal_validation_strategy( ref self, input.proposal_validation_strategy.clone() ); @@ -693,7 +679,7 @@ mod Space { ); } - if NoUpdateArray::should_update((@input).authenticators_to_add) { + if input.authenticators_to_add.should_update() { _add_authenticators(ref self, input.authenticators_to_add.span()); self .emit( @@ -705,7 +691,7 @@ mod Space { ); } - if NoUpdateArray::should_update((@input).authenticators_to_remove) { + if input.authenticators_to_remove.should_update() { _remove_authenticators(ref self, input.authenticators_to_remove.span()); self .emit( @@ -717,7 +703,7 @@ mod Space { ); } - if NoUpdateArray::should_update((@input).voting_strategies_to_add) { + if input.voting_strategies_to_add.should_update() { _add_voting_strategies(ref self, input.voting_strategies_to_add.span()); self .emit( @@ -732,7 +718,7 @@ mod Space { ); } - if NoUpdateArray::should_update((@input).voting_strategies_to_remove) { + if input.voting_strategies_to_remove.should_update() { _remove_voting_strategies(ref self, input.voting_strategies_to_remove.span()); self .emit( @@ -743,6 +729,21 @@ mod Space { ) ); } + + // TODO: test once #506 is merged + if NoUpdateString::should_update((@input).metadata_URI) { + self + .emit( + Event::MetadataUriUpdated( + MetadataUriUpdated { metadata_URI: input.metadata_URI.span() } + ) + ); + } + + // TODO: test once #506 is merged + if NoUpdateString::should_update((@input).dao_URI) { + self.emit(Event::DaoUriUpdated(DaoUriUpdated { dao_URI: input.dao_URI.span() })); + } } fn vote_power(self: @ContractState, proposal_id: u256, choice: Choice) -> u256 { diff --git a/starknet/src/types.cairo b/starknet/src/types.cairo index a5662b4b..e1237da8 100644 --- a/starknet/src/types.cairo +++ b/starknet/src/types.cairo @@ -23,4 +23,5 @@ mod update_settings_calldata; use update_settings_calldata::{ UpdateSettingsCalldata, UpdateSettingsCalldataImpl, UpdateSettingsCalldataTrait, NoUpdateArray, NoUpdateContractAddress, NoUpdateFelt252, NoUpdateStrategy, NoUpdateTrait, NoUpdateU32, + NoUpdateString, }; diff --git a/starknet/src/types/update_settings_calldata.cairo b/starknet/src/types/update_settings_calldata.cairo index 3c6588c7..da73883e 100644 --- a/starknet/src/types/update_settings_calldata.cairo +++ b/starknet/src/types/update_settings_calldata.cairo @@ -79,6 +79,21 @@ impl NoUpdateStrategy of NoUpdateTrait { } } +impl NoUpdateString of NoUpdateTrait> { + fn no_update() -> Array { + array!['No update'] + } + + fn should_update(self: @Array) -> bool { + match self.get(0) { + Option::Some(e) => { + *e.unbox() == 'No update' + }, + Option::None => false, + } + } +} + // TODO: find a way for "Strings" impl NoUpdateArray of NoUpdateTrait> { fn no_update() -> Array {