Skip to content

Commit

Permalink
use correct syntax for no_update (#528)
Browse files Browse the repository at this point in the history
* use correct syntax for no_update

* add NoUpdateString
  • Loading branch information
pscott authored Aug 31, 2023
1 parent 1753f01 commit 04bda8f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
49 changes: 25 additions & 24 deletions starknet/src/space/space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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()
);
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions starknet/src/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ mod update_settings_calldata;
use update_settings_calldata::{
UpdateSettingsCalldata, UpdateSettingsCalldataImpl, UpdateSettingsCalldataTrait, NoUpdateArray,
NoUpdateContractAddress, NoUpdateFelt252, NoUpdateStrategy, NoUpdateTrait, NoUpdateU32,
NoUpdateString,
};
15 changes: 15 additions & 0 deletions starknet/src/types/update_settings_calldata.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ impl NoUpdateStrategy of NoUpdateTrait<Strategy> {
}
}

impl NoUpdateString of NoUpdateTrait<Array<felt252>> {
fn no_update() -> Array<felt252> {
array!['No update']
}

fn should_update(self: @Array<felt252>) -> bool {
match self.get(0) {
Option::Some(e) => {
*e.unbox() == 'No update'
},
Option::None => false,
}
}
}

// TODO: find a way for "Strings"
impl NoUpdateArray<T> of NoUpdateTrait<Array<T>> {
fn no_update() -> Array<T> {
Expand Down

0 comments on commit 04bda8f

Please sign in to comment.