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

Added entry_points! macro to reduce boilerplate when writing contracts #437

Merged
merged 7 commits into from
Jun 22, 2020

Conversation

reuvenpo
Copy link
Contributor

@reuvenpo reuvenpo commented Jun 21, 2020

I wrote this macro to allow us to reduce boilerplate when writing our own contracts, and figured it would be a good idea to suggest it upstream.

It's not the most flexible macro ever (and trust me, I know how to make macros flexible) but i had trouble taking the paths to the implementation functions or even just to the contract module itself in a flexible way because of a weird limitation of macro rules.

I added a doc-comment to the macro definition, and replaced the boilerplate in the example contracts to showcase the macro.

To illustrate, hackatom's lib.rs file now looks like this:

pub mod contract;

#[cfg(target_arch = "wasm32")]
cosmwasm_std::entry_points_with_migration!(contract);

Update: looks like I can't always require migrate to exist. I'll try to make that work.
Update: Done.

@reuvenpo reuvenpo requested a review from webmaster128 June 21, 2020 15:22
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Very good

packages/std/src/entry_points.rs Outdated Show resolved Hide resolved
packages/std/src/entry_points.rs Outdated Show resolved Hide resolved
packages/std/src/entry_points.rs Show resolved Hide resolved
packages/std/src/entry_points.rs Outdated Show resolved Hide resolved
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Can you update MIGRATING.md and make a PR on cosmwasm-template with this change? (Actually we need a whole 0.9 branch there, so maybe the comswasm-template stuff can come later)

@webmaster128 webmaster128 merged commit 65df0f0 into master Jun 22, 2020
@webmaster128 webmaster128 deleted the entry-point-macro branch June 22, 2020 09:03
@reuvenpo
Copy link
Contributor Author

Sooo... Should I do any of those things or not?

@webmaster128
Copy link
Member

Sooo... Should I do any of those things or not?

No, thanks. I'll take care of that.

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.

3 participants