You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue comes from the need to simplify smart contract development on Dusk by abstracting away implementation details like the static mut STATE and no_mangle functions.
We can create a #[contract] macro that generates the necessary boilerplate code automatically. We can take and extend the functionality of the piecrust-macros I did here, and make it do the following:
The #[contract] macro should be applicable to a Rust module.
The macro should generate no_mangle functions for all public methods within impl blocks.
The macro should generate no_mangle functions for every trait implementation function.
The macro should automatically generate static mut STATE for a public struct defined within the module.
How the static mut STATE gets created should also be standardised and defined. Otherwise it will be unclear how certain data structures within the field of the struct would be created and with which values.
The simplest approach here, in my opinion, would be to require the Default trait to be implemented for the public struct. This way the macro can always create the state with the default() method.
(There could also be another way with the init() function)
I think the name of this repo, "dev-tools" is not specific and generic, ideally this macro we're making should be moved in the rusk mono repo and used by the genesis contracts and exported from there like execution-core is (we will also need types from execution-core so better to have it in the workspace)
I would get a prototype of what Hein developed, out there, let me know if you need help or want me to create the macro package and export it for use with the rusk wallet @HDauven@Neotamandua
Summary
This issue comes from the need to simplify smart contract development on Dusk by abstracting away implementation details like the
static mut STATE
andno_mangle
functions.It follows from the discussion in the issue Investigate foreign trait exposing.
Possible solution design or implementation
We can create a
#[contract]
macro that generates the necessary boilerplate code automatically. We can take and extend the functionality of the piecrust-macros I did here, and make it do the following:#[contract]
macro should be applicable to a Rust module.no_mangle
functions for all public methods withinimpl
blocks.no_mangle
functions for every trait implementation function.static mut STATE
for a public struct defined within the module.Example
The following input:
Should generate the following output:
By implementing this feature set, developers no longer need to create the
no_mangle
functions and do not have to define the state explicitly.The text was updated successfully, but these errors were encountered: