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

Add require macro #1103

Closed
ethanfrey opened this issue Sep 23, 2021 · 7 comments · Fixed by #1127
Closed

Add require macro #1103

ethanfrey opened this issue Sep 23, 2021 · 7 comments · Fixed by #1127

Comments

@ethanfrey
Copy link
Member

Suggestion from Twitter: https://twitter.com/gakonst/status/1440428252267376659?s=21

macros to reduce verbosity for very common operations is one (eg if !condition { return Err("some error string")} should really be require!(condition, "some error string"))

A more concrete example where we could do codeine, taking:

require!(info.sender == cfg.admin, ContractErr::Unauthorized{});

that generates something like:

if ! (info.sender == cfg.admin) {
    return Err(ContractErr::Unauthorized{});
}

Maybe this macro exists in a standard Rust package already and using it in sample contracts we could highlight it.

@webmaster128
Copy link
Member

Makes sense. It's a pitty we don't get panic messages when compiling to Wasm because Rust already provides those types of tings (assert!(condition, "message");).

@ethanfrey
Copy link
Member Author

Maybe for 1.0?

@webmaster128
Copy link
Member

This is a compatible addition and can be done at any time

@ethanfrey
Copy link
Member Author

This is basically what ensure! does

@ethanfrey
Copy link
Member Author

Sure, no need to get it in 1.0. I want to use it soonish... will add to cw-plus

@webmaster128
Copy link
Member

Happy to pull it in for maintenance from CosmWasm/cw-plus#469 when we see it works well in the caller code and devs like it.

@ethanfrey
Copy link
Member Author

Great idea.
Let's get some feedback and quick iteration in cw-plus, then pull it into cosmwasm_std when it is stabilised

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.

2 participants