-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* core: upgradeable component wip * #[dojo::contract] merge Event, update upgradeable * update base_test.cairo & dojo-lang plugin_test_data * add Upgraded event in upgradeable component * move erc20, fix build issue, delete old tests * update erc20 to use #[dojo::contract] * revert changes on erc20 * revert changes on erc20 * fully qualify component * handle when Event is not defined in contract * follow clippy recomandation * torii: update records_contract address * trigger CI * trigger CI * rebase main * update manifest_test_data * use right records_contract address
- Loading branch information
Showing
11 changed files
with
531 additions
and
180 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
mod upgradeable; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use starknet::ClassHash; | ||
|
||
#[starknet::interface] | ||
trait IUpgradeable<T> { | ||
fn upgrade(ref self: T, new_class_hash: ClassHash); | ||
} | ||
|
||
#[starknet::component] | ||
mod upgradeable { | ||
use starknet::ClassHash; | ||
use starknet::ContractAddress; | ||
use starknet::get_caller_address; | ||
use starknet::syscalls::replace_class_syscall; | ||
use dojo::world::{IWorldProvider, IWorldProviderDispatcher, IWorldDispatcher}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
Upgraded: Upgraded, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct Upgraded { | ||
class_hash: ClassHash | ||
} | ||
|
||
mod Errors { | ||
const INVALID_CLASS: felt252 = 'class_hash cannot be zero'; | ||
const INVALID_CALLER: felt252 = 'must be called by world'; | ||
const INVALID_WORLD_ADDRESS: felt252 = 'invalid world address'; | ||
} | ||
|
||
#[embeddable_as(UpgradableImpl)] | ||
impl Upgradable< | ||
TContractState, +HasComponent<TContractState>, +IWorldProvider<TContractState> | ||
> of super::IUpgradeable<ComponentState<TContractState>> { | ||
fn upgrade(ref self: ComponentState<TContractState>, new_class_hash: ClassHash) { | ||
assert( | ||
self.get_contract().world().contract_address.is_non_zero(), | ||
Errors::INVALID_WORLD_ADDRESS | ||
); | ||
assert( | ||
get_caller_address() == self.get_contract().world().contract_address, | ||
Errors::INVALID_CALLER | ||
); | ||
assert(new_class_hash.is_non_zero(), Errors::INVALID_CLASS); | ||
|
||
replace_class_syscall(new_class_hash).unwrap(); | ||
|
||
self.emit(Upgraded { class_hash: new_class_hash }); | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.