-
Notifications
You must be signed in to change notification settings - Fork 358
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
Migrate Initializable to component #764
Migrate Initializable to component #764
Conversation
src/security/initializable.cairo
Outdated
/// SPDX-License-Identifier: MIT | ||
/// OpenZeppelin Contracts for Cairo v0.7.0 (security/initializable.cairo) | ||
/// | ||
/// # Initializable Component | ||
/// | ||
/// The Initializable component provides a simple mechanism that executes | ||
/// logic once and only once. This can be useful for setting a contract's | ||
/// initial state in scenarios where a constructor cannot be used. |
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.
/// SPDX-License-Identifier: MIT | |
/// OpenZeppelin Contracts for Cairo v0.7.0 (security/initializable.cairo) | |
/// | |
/// # Initializable Component | |
/// | |
/// The Initializable component provides a simple mechanism that executes | |
/// logic once and only once. This can be useful for setting a contract's | |
/// initial state in scenarios where a constructor cannot be used. | |
//! SPDX-License-Identifier: MIT | |
//! OpenZeppelin Contracts for Cairo v0.7.0 (security/initializable.cairo) | |
//! | |
//! # Initializable Component | |
//! | |
//! The Initializable component provides a simple mechanism that executes | |
//! logic once and only once. This can be useful for setting a contract's | |
//! initial state in scenarios where a constructor cannot be used. |
src/security/initializable.cairo
Outdated
trait InternalTrait<TContractState> { | ||
fn is_initialized(self: @TContractState) -> bool; | ||
fn initialize(ref self: TContractState); | ||
} | ||
|
||
impl InternalImpl< | ||
TContractState, +HasComponent<TContractState> | ||
> of InternalTrait<ComponentState<TContractState>> { |
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.
trait InternalTrait<TContractState> { | |
fn is_initialized(self: @TContractState) -> bool; | |
fn initialize(ref self: TContractState); | |
} | |
impl InternalImpl< | |
TContractState, +HasComponent<TContractState> | |
> of InternalTrait<ComponentState<TContractState>> { | |
#[generate_trait] | |
impl InternalImpl< | |
TContractState, +HasComponent<TContractState> | |
> of InternalTrait<TContractState> { |
@@ -0,0 +1,19 @@ | |||
#[starknet::contract] | |||
mod InitializableMock { | |||
use openzeppelin::security::initializable::Initializable as initializable_comp; |
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.
use openzeppelin::security::initializable::Initializable as initializable_comp; | |
use openzeppelin::security::initializable::Initializable as initializable_component; |
component!(path: initializable_comp, storage: initializable, event: InitializableEvent); | ||
impl InternalImpl = initializable_comp::InternalImpl<ContractState>; |
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.
component!(path: initializable_comp, storage: initializable, event: InitializableEvent); | |
impl InternalImpl = initializable_comp::InternalImpl<ContractState>; | |
component!(path: initializable_comp, storage: initializable, event: InitializableEvent); | |
impl InternalImpl = initializable_comp::InternalImpl<ContractState>; |
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
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.
LGTM!
Supersedes #758 and fixes #757.