From e8cfc9081dc6965c4fb5367522df46270e0b6fa0 Mon Sep 17 00:00:00 2001 From: Mehul Chauhan Date: Fri, 6 Sep 2024 05:06:46 +0530 Subject: [PATCH] feat: add upgradeability (#36) * feat: add upgradeability * update comments * fix: run scarb fmt --------- Co-authored-by: glihm --- src/appchain.cairo | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/appchain.cairo b/src/appchain.cairo index eaf1043..47e3d73 100644 --- a/src/appchain.cairo +++ b/src/appchain.cairo @@ -21,6 +21,10 @@ mod appchain { ReentrancyGuardComponent, ReentrancyGuardComponent::InternalTrait as InternalReentrancyGuardImpl }; + use openzeppelin::upgrades::{ + UpgradeableComponent as upgradeable_cpt, + UpgradeableComponent::InternalTrait as UpgradeableInternal, interface::IUpgradeable + }; use piltover::components::onchain_data_fact_tree_encoder::{ encode_fact_with_onchain_data, DataAvailabilityFact }; @@ -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); @@ -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, @@ -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, @@ -197,4 +206,12 @@ mod appchain { ); } } + + #[abi(embed_v0)] + impl UpgradeableImpl of IUpgradeable { + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { + self.ownable.assert_only_owner(); + self.upgradeable._upgrade(new_class_hash); + } + } }