Skip to content

Commit

Permalink
add gatekeeper storage view functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zkcarter committed Aug 31, 2023
1 parent af3398e commit 8864445
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/contracts/gatekeeper.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use starknet::{ContractAddress, ClassHash};
use zklink::utils::data_structures::DataStructures::UpgradeStatus;

#[starknet::interface]
trait IUpgradeGateKeeper<TContractState> {
Expand All @@ -8,6 +9,14 @@ trait IUpgradeGateKeeper<TContractState> {
fn startUpgrade(ref self: TContractState, _newTargets: Array<ClassHash>);
fn finishUpgrade(ref self: TContractState) -> bool;
fn cancelUpgrade(ref self: TContractState);
fn upgradeStatus(self: @TContractState) -> UpgradeStatus;
fn mainContract(self: @TContractState) -> ContractAddress;
fn managedContracts(self: @TContractState, _index: usize) -> ContractAddress;
fn managedContractsLength(self: @TContractState) -> usize;
fn noticePeriodFinishTimestamp(self: @TContractState) -> u256;
fn nextTargets(self: @TContractState, _index: usize) -> ClassHash;
fn nextTargetsLength(self: @TContractState) -> usize;
fn versionId(self: @TContractState) -> u256;
}

#[starknet::contract]
Expand All @@ -28,7 +37,7 @@ mod UpgradeGateKeeper {
mainContract: ContractAddress,
// public, Array of addresses of upgradeable contracts managed by the gatekeeper
managedContracts: LegacyMap::<usize, ContractAddress>,
// internal, managedContracts length
// public, managedContracts length
managedContractsLength: usize,
// public, upgrade status
upgradeStatus: UpgradeStatus,
Expand All @@ -38,7 +47,7 @@ mod UpgradeGateKeeper {
// public, Addresses of the next versions of the contracts to be upgraded (if element of this array is equal to zero address it means that appropriate upgradeable contract wouldn't be upgraded this time)
// Will be empty in case of not active upgrade mode
nextTargets: LegacyMap::<usize, ClassHash>,
// internal, nextTargets length
// public, nextTargets length
nextTargetsLength: usize,
// public, Version id of contracts
versionId: u256
Expand Down Expand Up @@ -258,6 +267,38 @@ mod UpgradeGateKeeper {

self.emit(Event::UpgradeCancel(UpgradeCancel { versionId: self.versionId.read() }))
}

fn upgradeStatus(self: @ContractState) -> UpgradeStatus {
self.upgradeStatus.read()
}

fn mainContract(self: @ContractState) -> ContractAddress {
self.mainContract.read()
}

fn managedContracts(self: @ContractState, _index: usize) -> ContractAddress {
self.managedContracts.read(_index)
}

fn managedContractsLength(self: @ContractState) -> usize {
self.managedContractsLength.read()
}

fn noticePeriodFinishTimestamp(self: @ContractState) -> u256 {
self.noticePeriodFinishTimestamp.read()
}

fn nextTargets(self: @ContractState, _index: usize) -> ClassHash {
self.nextTargets.read(_index)
}

fn nextTargetsLength(self: @ContractState) -> usize {
self.nextTargetsLength.read()
}

fn versionId(self: @ContractState) -> u256 {
self.versionId.read()
}
}

#[generate_trait]
Expand Down

0 comments on commit 8864445

Please sign in to comment.