Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add upgradeability #36

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/appchain.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ mod appchain {
OwnableComponent as ownable_cpt, OwnableComponent::InternalTrait as OwnableInternal,
interface::IOwnable
};
use openzeppelin::upgrades::{
UpgradeableComponent as upgradeable_cpt,
UpgradeableComponent::InternalTrait as UpgradeableInternal, interface::IUpgradeable
};
use openzeppelin::security::reentrancyguard::{
ReentrancyGuardComponent,
ReentrancyGuardComponent::InternalTrait as InternalReentrancyGuardImpl
Expand All @@ -37,13 +41,14 @@ mod appchain {
use piltover::snos_output;
use piltover::state::component::state_cpt::HasComponent;
use piltover::state::{state_cpt, state_cpt::InternalTrait as StateInternal, IState};
use starknet::ContractAddress;
use starknet::{ContractAddress, ClassHash};
use super::errors;

/// The default cancellation delay of 5 days.
const CANCELLATION_DELAY_SECS: u64 = 432000;

component!(path: ownable_cpt, storage: ownable, event: OwnableEvent);
component!(path: upgradeable_cpt, storage: upgradeable, event: UpgradeableEvent);
component!(path: config_cpt, storage: config, event: ConfigEvent);
component!(path: messaging_cpt, storage: messaging, event: MessagingEvent);
component!(path: state_cpt, storage: state, event: StateEvent);
Expand All @@ -63,6 +68,8 @@ mod appchain {
#[substorage(v0)]
ownable: ownable_cpt::Storage,
#[substorage(v0)]
upgradeable: upgradeable_cpt::Storage,
#[substorage(v0)]
config: config_cpt::Storage,
#[substorage(v0)]
messaging: messaging_cpt::Storage,
Expand All @@ -78,6 +85,8 @@ mod appchain {
#[flat]
OwnableEvent: ownable_cpt::Event,
#[flat]
UpgradeableEvent: upgradeable_cpt::Event,
#[flat]
ConfigEvent: config_cpt::Event,
#[flat]
MessagingEvent: messaging_cpt::Event,
Expand Down Expand Up @@ -197,4 +206,12 @@ mod appchain {
);
}
}

#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable._upgrade(new_class_hash);
}
}
}
Loading