-
Notifications
You must be signed in to change notification settings - Fork 20
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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,15 @@ mod appchain { | |
); | ||
} | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl UpgradeableImpl of IUpgradeable<ContractState> { | ||
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { | ||
// This function can only be called by the owner | ||
self.ownable.assert_only_owner(); | ||
|
||
// Replace the class hash upgrading the contract | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, comment could be removed as very self-explanatory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
self.upgradeable._upgrade(new_class_hash); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment that could be removed as code is self-explanatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated