Skip to content

Commit

Permalink
feat: add upgradeability (#36)
Browse files Browse the repository at this point in the history
* feat: add upgradeability

* update comments

* fix: run scarb fmt

---------

Co-authored-by: glihm <[email protected]>
  • Loading branch information
byteZorvin and glihm authored Sep 5, 2024
1 parent 517ea2b commit e8cfc90
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/appchain.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
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);
}
}
}

0 comments on commit e8cfc90

Please sign in to comment.