-
Notifications
You must be signed in to change notification settings - Fork 181
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
Define a macro for extending CW721 execute/query messages #90
Comments
Love this. ❤️ Everyone hates the extension pattern, would allow us to simplify a lot of stuff. 😂 |
This greatly simplifies things for the developer that knows what's going on under the hood. But what about a noob dev that doesn't? |
Great to see this solution by @0xekez / the DAO DAO team. Some thoughts:
|
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem
cw721::ExecuteMsg
defines a minimum set of execute methods that all CW-721 variants are expected to implement. However, projects often want to extend it by adding their own methods. For example,cw721-base
adds "mint" and "burn" methods. The process for adding these methods is rather cumbersome, for example:Imo, there are two drawbacks with this approach:
TransferNft
is omitted by mistake? Preferably we want an error to be thrown at compile time to alert the developer that they forgot something.)Proposed solution
@0xekez showed me it is possible to "autofill" an enum with some pre-defined variants by a macro, which is an approach already used by DAO DAO: https://github.com/DA0-DA0/dao-contracts/blob/main/packages/cwd-macros/src/lib.rs
I propose we create a
#[cw721_execute]
macro that if used the following way:Will transform the enum to:
This prevents the developer to have to copy all the CW721 enum variants over, and enforces all variants are included. Additionally,
#[cw_serde]
is automatically applied.In the
cw721
crate, the execute message can simply be defined as:Further suggestion
It'd be even better if the following traits can be automatically implemented as well:
This makes it much easier to implement
execute
entry point:Notes
cw721::ExecuteMsg::Extension
method as it is no longer needed.The text was updated successfully, but these errors were encountered: