Skip to content

Commit

Permalink
feat(x/intent)!: ability for modules to dynamically resolve variables…
Browse files Browse the repository at this point in the history
… on Action creation (#139)

* feat(wardend): prefer context.Context over sdk.Context where possible

This allow us to pass other context to functions. In the future we might
exploit this feature for enriching the sdk.Context with more fields.

* feat(shield): move Environment interface out of internal package

Even if it was type-aliased (= re-exported), the depinject pkg from
Cosmos SDK didn't like it. Since Environment is commonly accessed from
outside of shield, it makes sense to move it outside the internal/ dir
anyway.

* feat(shield): allow dots (.) in identifier names

In this version of shield we'll treat dots as part of the identifier
(i.e. we won't dig much into building "javascript objects" equivalents).
It'll be up to the Environment resolving the identifier to do whatever
it prefers.

E.g. `warden.space.owners` will be treated as a single name. The
resolution env from x/warden can split by '.' and resolve 'space'
properties individually.

* chore(shield): move `ast` outside internal folder

* feat(shield): add custom AST preprocessing

This allows anyone to plug-in an implementer of the Expander interface
to change the AST into another AST by replacing any Identifier with
another AST node.

This will be useful for resolving some Identifiers into Warden addresses
and freeze them in time (e.g. when an Action is created).

* feat(shield): add ast.Stringify method to translate an AST back into its string definition

* feat(x/intent): inject a constructor for a shield.Expander

We'll use the Expander later, when creating an Action, to process the
Intent definition at the time the Action is created.

* feat(x/intent): provide an ast.Expander implementation

The ExpanderManager will dispatch Expander calls based on "namespace",
i.e. the first part of an identifier (separated by a dot).

* fix(x/intent): don't run preprocessors when evaluating the Intent

* feat(x/intent): move and rename Intent.Addresses to Action.Mentions

This way we can populate this field *after* preprocessing. The Intent
stored in the database will have the original definition written by the
user, the Intent stored inside the Action will be preprocessed (so the
user knows exactly what's being evaluated to decide on its Action).

* feat(x/intent): extend a Context adding the Action msg being processed

* feat(x/intent): freeze Intent after preprocessing during Action creation

* chore: remove older migrations code

* feat(x/warden): provide shield.Expander for warden module

In this initial version, it's able to expand `space.owners` in the list
of owners for the space.
Only sdk.Msgs that have a SpaceId field are supported at this time.

* feat(x/warden): rewrite the default intent using the new language features

* chore: changelog

* Update warden/x/warden/keeper/shield.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: fix changelog scope

* feat: proper error handling for ast.Expanders

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
Pitasi and coderabbitai[bot] authored Apr 4, 2024
1 parent 3c17012 commit eebb290
Show file tree
Hide file tree
Showing 36 changed files with 774 additions and 461 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Consensus Breaking Changes

* (x/intent) [#139](https://github.com/warden-protocol/wardenprotocol/pull/139) Ability for modules to dynamically resolve variables on Action creation
* x/warden can now resolve `warden.space.owners` in Intent definitions into the list of owners of the space

### Features

### Bug Fixes
Expand Down
189 changes: 162 additions & 27 deletions api/warden/intent/action.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eebb290

Please sign in to comment.