Open larry0x opened 1 year ago
Love this. :heart:
Everyone hates the extension pattern, would allow us to simplify a lot of stuff. :joy:
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:
#[cw721_execute]
is a bit short. I'd lean towards something like #[add_cw721_execute_cases]
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.