feat(commondao): extension to create callback based proposal definitions#5014
feat(commondao): extension to create callback based proposal definitions#5014jeronimoalbi wants to merge 12 commits intognolang:masterfrom
Conversation
Support defining executable proposal definitions which could be either crossing or non crossing. This is required to be able to define proposal types within pure packages, because crossing methods and functions can only be defined within realms. When a proposal definition is defined in a realm it can implement the crossing execution method, otherwise it must implement non crossing methods. Defining non crossing executable proposal types is useful when the proposal type is defined within a pure package where the definition execution is defined by a crossing callback for example. Technically it would also be possible that a proposal definition just updates local properties on execution, instead of realm state globals.
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
| A proposal can be executable implementing either the **Executable** interface | ||
| or the **CrossExecutable** one as part of the new proposal definition: | ||
|
|
||
| ```go | ||
| type Executable interface { | ||
| // Execute executes the proposal. | ||
| Execute() error | ||
| } | ||
|
|
||
| type CrossExecutable interface { | ||
| // Execute executes the proposal. | ||
| Execute(realm) error | ||
| } | ||
| ``` | ||
|
|
||
| **CrossExecutable** can only be implemented when the proposal definition is | ||
| defined within a realm instead of a package, Gno only allows defining crossing | ||
| functions and methods within realms. So, executable proposal definitions | ||
| defined within packages must implement **Executable** instead, and when | ||
| crossing is required it must be done explicitly within the `Execute()` method. |
There was a problem hiding this comment.
Updated commondao to allow proposal definitions to be executable without having to be defined as crossing.
This was required to be able to define a proposal definition within a package.
This opens up two possibilities, one is to define new proposal types within realms, as it was the case until now, and the other to define them within a package. When defined within a package crossing must be done explicitly, for example within the Execute() error method.
There was a problem hiding this comment.
I don't think this should be supported; or if it is, a proposal should first go through a realm, and then that realm calls the pure package
Co-authored-by: MikaelVallenet <mikael.vallenetpro@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| case Executable: | ||
| err = e.Execute() | ||
| case CrossExecutable: | ||
| err = e.Execute(cross) |
There was a problem hiding this comment.
I don't think we should add this. Proposals should be assumed to be potentially malicious, so I would always cross-call them. Any specific use case?
| A proposal can be executable implementing either the **Executable** interface | ||
| or the **CrossExecutable** one as part of the new proposal definition: | ||
|
|
||
| ```go | ||
| type Executable interface { | ||
| // Execute executes the proposal. | ||
| Execute() error | ||
| } | ||
|
|
||
| type CrossExecutable interface { | ||
| // Execute executes the proposal. | ||
| Execute(realm) error | ||
| } | ||
| ``` | ||
|
|
||
| **CrossExecutable** can only be implemented when the proposal definition is | ||
| defined within a realm instead of a package, Gno only allows defining crossing | ||
| functions and methods within realms. So, executable proposal definitions | ||
| defined within packages must implement **Executable** instead, and when | ||
| crossing is required it must be done explicitly within the `Execute()` method. |
There was a problem hiding this comment.
I don't think this should be supported; or if it is, a proposal should first go through a realm, and then that realm calls the pure package
Adds a
gno.land/p/nt/commondao/exts/definitionpackage which is an extension ofgno.land/p/nt/commondaothat provides an alternative approach for creating custom proposal types.The main CommonDAO package supports different proposal types though the
ProposalDefinitioninterface, so new proposal types require the definition of a custom type that implements this interface. TheDefinitiontype introduced in the newdefinitionextension package is a callback based alternative to the type based approach offered by CommonDAO.Custom proposal definitions can be created using any of the following public package functions:
Default definition behavior can be configured by using custom options that configures the following proposal parameters: