Skip to content

Commit

Permalink
Feat: Validator Announce storage location as array (#57)
Browse files Browse the repository at this point in the history
* feat: storage location concat

* fix: format code

* fix: storage location as LegacyMap

* feat: coverage test

* fix: format code
  • Loading branch information
JordyRo1 authored Jul 3, 2024
1 parent d9152fc commit 2e40089
Show file tree
Hide file tree
Showing 4 changed files with 566 additions and 90 deletions.
22 changes: 17 additions & 5 deletions contracts/src/contracts/isms/multisig/validator_announce.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub mod validator_announce {
ownable: OwnableComponent::Storage,
#[substorage(v0)]
upgradeable: UpgradeableComponent::Storage,
storage_location: LegacyMap::<EthAddress, Array<felt252>>,
storage_location_len: LegacyMap::<EthAddress, u256>,
storage_locations: LegacyMap::<(EthAddress, u256), Array<felt252>>,
replay_protection: LegacyMap::<felt252, bool>,
validators: LegacyMap::<EthAddress, EthAddress>,
}
Expand Down Expand Up @@ -138,8 +139,9 @@ pub mod validator_announce {
self.validators.write(last_validator, _validator);
}
};

self.storage_location.write(_validator, _storage_location);
let mut validator_len = self.storage_location_len.read(_validator);
self.storage_locations.write((_validator, validator_len), _storage_location);
self.storage_location_len.write(_validator, validator_len + 1);
self.replay_protection.write(replay_id, true);
self
.emit(
Expand All @@ -162,12 +164,22 @@ pub mod validator_announce {
/// Span<Span<felt252>> - A list of registered storage metadata
fn get_announced_storage_locations(
self: @ContractState, mut _validators: Span<EthAddress>
) -> Span<Span<felt252>> {
) -> Span<Span<Array<felt252>>> {
let mut metadata = array![];
loop {
match _validators.pop_front() {
Option::Some(validator) => {
let validator_metadata = self.storage_location.read(*validator);
let mut cur_idx = 0;
let validator_len = self.storage_location_len.read(*validator);
let mut validator_metadata = array![];
loop {
if (cur_idx == validator_len) {
break ();
}
validator_metadata
.append(self.storage_locations.read((*validator, cur_idx)));
cur_idx += 1;
};
metadata.append(validator_metadata.span())
},
Option::None => { break (); }
Expand Down
Loading

0 comments on commit 2e40089

Please sign in to comment.