Skip to content
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

Merged
merged 10 commits into from
Oct 12, 2023

Conversation

andrew-fleming
Copy link
Collaborator

Supersedes #758 and fixes #757.

Comment on lines 1 to 8
/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.

Comment on lines 20 to 27
trait InternalTrait<TContractState> {
fn is_initialized(self: @TContractState) -> bool;
fn initialize(ref self: TContractState);
}

impl InternalImpl<
TContractState, +HasComponent<TContractState>
> of InternalTrait<ComponentState<TContractState>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use openzeppelin::security::initializable::Initializable as initializable_comp;
use openzeppelin::security::initializable::Initializable as initializable_component;

Comment on lines 5 to 6
component!(path: initializable_comp, storage: initializable, event: InitializableEvent);
impl InternalImpl = initializable_comp::InternalImpl<ContractState>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>;

src/tests/utils.cairo Outdated Show resolved Hide resolved
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@andrew-fleming andrew-fleming merged commit 0b77977 into OpenZeppelin:main Oct 12, 2023
@andrew-fleming andrew-fleming deleted the add-init-components branch October 12, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Initializable to component
2 participants