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

macros for init and callable methods #106

Open
geofmureithi opened this issue Nov 15, 2023 · 1 comment
Open

macros for init and callable methods #106

geofmureithi opened this issue Nov 15, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@geofmureithi
Copy link
Contributor

Is your feature request related to a problem? Please describe.
In almost all our contracts we have this code:

pub fn init(env: Env, some: Params) {
        let storage = env.storage().persistent();
        if storage.get::<_, ()>(&DataKey::Initialized).is_some() {
            panic_with_error!(&env, Error::AlreadyInitialized);
        }
}
pub fn callable_method(env: Env, some: Params) {
        let storage = env.storage().persistent();
        if storage.get::<_, ()>(&DataKey::Initialized).is_none() {
            panic_with_error!(&env, Error::NotInitialized);
        }

Describe the solution you'd like
We could have some utilities macros:

#[init]
pub fn init(env: Env, some: Params) { ... }
#[must_init]
pub fn callable_method(env: Env, some: Params) { ... }

Additional context
Of course the naming can be different but hopefully this gets the point home.

@eloylp
Copy link
Member

eloylp commented Nov 15, 2023

This looks great ! My vote for moving this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants