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

Allow storage access in SNIP12Metadata #1023

Closed
ericnordelo opened this issue Jun 26, 2024 · 1 comment · Fixed by #1036
Closed

Allow storage access in SNIP12Metadata #1023

ericnordelo opened this issue Jun 26, 2024 · 1 comment · Fixed by #1036

Comments

@ericnordelo
Copy link
Member

🧐 Motivation
Currently, we can't dynamically set the name and version when implementing SNIP12, but we need to set them as constant short strings. This intentionally saves some gas by avoiding unnecessary storage reads, but sometimes that's the desired behavior, like for example, with a token generator.

📝 Details
Make the SNIP12Metadata trait generic on the contract state, so it can optionally access storage members.

@ericnordelo
Copy link
Member Author

This is already achievable by using unsafe_new_contract_state, or the StoragePath trait from Cairo 2.7:


use openzeppelin::utils::snip12::SNIP12Metadata;

impl SNIP12MetadataImpl of SNIP12Metadata {
    fn name() -> felt252 {
        let state = unsafe_new_contract_state();

        // Some logic to get the name from storage
        state.erc20.name().at(0).unwrap().into()
    }

    fn version() -> felt252 { 'v1' }
}

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 a pull request may close this issue.

1 participant