Skip to content
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

refactor: Add basic GetChainInfo method to plugin API #3561

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f82b838
refactor: Analyzer/analizer -> ClientAPI
clockworkgr Jun 23, 2023
51efa6d
refactor: rename proto files and rebuild
clockworkgr Jun 23, 2023
eb09d19
Merge branch 'feat/plugin-system-improvements-versioning-analysis' in…
clockworkgr Jul 3, 2023
70bb246
refactor: Add json tags
clockworkgr Jul 4, 2023
b733320
wip/refactor: Module analysis
clockworkgr Jul 7, 2023
0a183f5
feat: Add chain reference to plugin ClientAPI
clockworkgr Jul 15, 2023
43af937
feat: Complete Dependencies ClientAPI method
clockworkgr Jul 17, 2023
5bec995
fix: Address review comments
clockworkgr Aug 8, 2023
fa13c9c
feat: Remove services/chain dep from pkg/cosmosanalysis as per discus…
clockworkgr Aug 8, 2023
13f2b90
wip: remove deptools install
clockworkgr Aug 29, 2023
6042bfd
feat: package-specific includes
clockworkgr Sep 4, 2023
e07b00d
fix: Replace Module List call with Chain Info call
clockworkgr Sep 4, 2023
eaa8d28
chore: Remove chain analysis code
clockworkgr Sep 4, 2023
0977ce4
feat: ChainInfo API example template
clockworkgr Sep 4, 2023
8feac24
chore: Update template cli reference
clockworkgr Sep 4, 2023
f2ef1a3
chore: clean up PR
clockworkgr Sep 4, 2023
732fe0b
fix: Address review comments
clockworkgr Sep 4, 2023
5f3ceca
Merge branch 'feat/plugin-system-improvements-versioning-analysis' in…
clockworkgr Sep 4, 2023
8663978
fix: address review comments
clockworkgr Sep 4, 2023
0f1bfa1
fix: address review comments
clockworkgr Sep 4, 2023
f1d31d1
fix: Tests and linting
clockworkgr Sep 4, 2023
3eaf39a
chore: add changelog
clockworkgr Sep 4, 2023
79cf45d
fix: linting issues
clockworkgr Sep 4, 2023
c6e8204
tests: fix issue with client api in plugin tests
jeronimoalbi Sep 5, 2023
fdf95a3
tests: fix plugin template for integration tests
jeronimoalbi Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- [#3544](https://github.com/ignite/cli/pull/3544) Add bidirectional communication to plugin system
- [#3561](https://github.com/ignite/cli/pull/3561) Add GetChainInfo method to plugin system API

### Changes

Expand Down
24 changes: 12 additions & 12 deletions docs/docs/plugins/02-dev-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,30 @@ type Interface interface {
// Execute will be invoked by ignite when a plugin Command is executed.
// It is global for all commands declared in Manifest, if you have declared
// multiple commands, use cmd.Path to distinguish them.
// The analizer argument can be used by plugins to get chain app analysis info.
Execute(context.Context, *ExecutedCommand, Analyzer) error
// The ClientAPI argument can be used by plugins to get chain app analysis info.
Execute(context.Context, *ExecutedCommand, ClientAPI) error

// ExecuteHookPre is invoked by ignite when a command specified by the Hook
// path is invoked.
// It is global for all hooks declared in Manifest, if you have declared
// multiple hooks, use hook.Name to distinguish them.
// The analizer argument can be used by plugins to get chain app analysis info.
ExecuteHookPre(context.Context, *ExecutedHook, Analyzer) error
// The ClientAPI argument can be used by plugins to get chain app analysis info.
ExecuteHookPre(context.Context, *ExecutedHook, ClientAPI) error

// ExecuteHookPost is invoked by ignite when a command specified by the hook
// path is invoked.
// It is global for all hooks declared in Manifest, if you have declared
// multiple hooks, use hook.Name to distinguish them.
// The analizer argument can be used by plugins to get chain app analysis info.
ExecuteHookPost(context.Context, *ExecutedHook, Analyzer) error
// The ClientAPI argument can be used by plugins to get chain app analysis info.
ExecuteHookPost(context.Context, *ExecutedHook, ClientAPI) error

// ExecuteHookCleanUp is invoked by ignite when a command specified by the
// hook path is invoked. Unlike ExecuteHookPost, it is invoked regardless of
// execution status of the command and hooks.
// It is global for all hooks declared in Manifest, if you have declared
// multiple hooks, use hook.Name to distinguish them.
// The analizer argument can be used by plugins to get chain app analysis info.
ExecuteHookCleanUp(context.Context, *ExecutedHook, Analyzer) error
// The ClientAPI argument can be used by plugins to get chain app analysis info.
ExecuteHookCleanUp(context.Context, *ExecutedHook, ClientAPI) error
}
```

Expand Down Expand Up @@ -160,7 +160,7 @@ To update the plugin execution, you have to change the plugin `Execute` command,
for instance :

```go
func (p) Execute(_ context.Context, cmd *plugin.ExecutedCommand, _ plugin.Analyzer) error {
func (p) Execute(_ context.Context, cmd *plugin.ExecutedCommand, _ plugin.ClientAPI) error {
if len(cmd.Args) == 0 {
return fmt.Errorf("oracle name missing")
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (p) Manifest(context.Context) (*plugin.Manifest, error) {
}, nil
}

func (p) ExecuteHookPre(_ context.Context, h *plugin.ExecutedHook, _ plugin.Analyzer) error {
func (p) ExecuteHookPre(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
switch h.Hook.GetName() {
case "my-hook":
fmt.Println("I'm executed before ignite chain build")
Expand All @@ -231,7 +231,7 @@ func (p) ExecuteHookPre(_ context.Context, h *plugin.ExecutedHook, _ plugin.Anal
return nil
}

func (p) ExecuteHookPost(_ context.Context, h *plugin.ExecutedHook, _ plugin.Analyzer) error {
func (p) ExecuteHookPost(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
switch h.Hook.GetName() {
case "my-hook":
fmt.Println("I'm executed after ignite chain build (if no error)")
Expand All @@ -241,7 +241,7 @@ func (p) ExecuteHookPost(_ context.Context, h *plugin.ExecutedHook, _ plugin.Ana
return nil
}

func (p) ExecuteHookCleanUp(_ context.Context, h *plugin.ExecutedHook, _ plugin.Analyzer) error {
func (p) ExecuteHookCleanUp(_ context.Context, h *plugin.ExecutedHook, _ plugin.ClientAPI) error {
switch h.Hook.GetName() {
case "my-hook":
fmt.Println("I'm executed after ignite chain build (regardless errors)")
Expand Down
30 changes: 25 additions & 5 deletions ignite/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@
}

execHook := newExecutedHook(hook, cmd, args)
err := p.Interface.ExecuteHookPre(ctx, execHook, plugin.NewAnalyzer())
c, err := newChainWithHomeFlags(cmd)
if err != nil {
return err
}

Check warning on line 213 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L212-L213

Added lines #L212 - L213 were not covered by tests
err = p.Interface.ExecuteHookPre(ctx, execHook, plugin.NewClientAPI(c))
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("plugin %q ExecuteHookPre() error: %w", p.Path, err)
}
Expand All @@ -223,7 +227,11 @@
if err != nil {
ctx := cmd.Context()
execHook := newExecutedHook(hook, cmd, args)
err := p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewAnalyzer())
c, err := newChainWithHomeFlags(cmd)
if err != nil {
return err
}
err = p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewClientAPI(c))

Check warning on line 234 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L230-L234

Added lines #L230 - L234 were not covered by tests
if err != nil {
fmt.Printf("plugin %q ExecuteHookCleanUp() error: %v", p.Path, err)
}
Expand All @@ -240,8 +248,12 @@
ctx := cmd.Context()
execHook := newExecutedHook(hook, cmd, args)

c, err := newChainWithHomeFlags(cmd)
if err != nil {
return err
}

Check warning on line 254 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L253-L254

Added lines #L253 - L254 were not covered by tests
defer func() {
err := p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewAnalyzer())
err := p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewClientAPI(c))
if err != nil {
fmt.Printf("plugin %q ExecuteHookCleanUp() error: %v", p.Path, err)
}
Expand All @@ -255,7 +267,11 @@
}
}

err := p.Interface.ExecuteHookPost(ctx, execHook, plugin.NewAnalyzer())
c, err = newChainWithHomeFlags(cmd)
if err != nil {
return err
}

Check warning on line 273 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L272-L273

Added lines #L272 - L273 were not covered by tests
Comment on lines +270 to +273
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this one can be removed, chain has been initialized already within this function definition

Suggested change
c, err = newChainWithHomeFlags(cmd)
if err != nil {
return err
}

err = p.Interface.ExecuteHookPost(ctx, execHook, plugin.NewClientAPI(c))
if err != nil {
return fmt.Errorf("plugin %q ExecuteHookPost() error : %w", p.Path, err)
}
Expand Down Expand Up @@ -327,7 +343,11 @@
}
execCmd.ImportFlags(cmd)
// Call the plugin Execute
err := p.Interface.Execute(ctx, execCmd, plugin.NewAnalyzer())
c, err := newChainWithHomeFlags(cmd)
if err != nil {
return err
}

Check warning on line 349 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L348-L349

Added lines #L348 - L349 were not covered by tests
err = p.Interface.Execute(ctx, execCmd, plugin.NewClientAPI(c))
// NOTE(tb): This pause gives enough time for go-plugin to sync the
// output from stdout/stderr of the plugin. Without that pause, this
// output can be discarded and not printed in the user console.
Expand Down
6 changes: 3 additions & 3 deletions ignite/cmd/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestLinkPluginCmds(t *testing.T) {
}),
mock.Anything,
).
Run(func(_ context.Context, execCmd *plugin.ExecutedCommand, _ plugin.Analyzer) {
Run(func(_ context.Context, execCmd *plugin.ExecutedCommand, _ plugin.ClientAPI) {
// Assert execCmd is populated correctly
assert.True(t, strings.HasSuffix(execCmd.Path, cmd.Use), "wrong path %s", execCmd.Path)
assert.Equal(t, args, execCmd.Args)
Expand Down Expand Up @@ -419,8 +419,8 @@ func TestLinkPluginHooks(t *testing.T) {
hook.PlaceHookOn == execHook.Hook.PlaceHookOn
})
}
asserter := func(hook *plugin.Hook) func(_ context.Context, hook *plugin.ExecutedHook, _ plugin.Analyzer) {
return func(_ context.Context, execHook *plugin.ExecutedHook, _ plugin.Analyzer) {
asserter := func(hook *plugin.Hook) func(_ context.Context, hook *plugin.ExecutedHook, _ plugin.ClientAPI) {
return func(_ context.Context, execHook *plugin.ExecutedHook, _ plugin.ClientAPI) {
assert.True(t, strings.HasSuffix(execHook.ExecutedCommand.Path, hook.PlaceHookOn), "wrong path %q want %q", execHook.ExecutedCommand.Path, hook.PlaceHookOn)
assert.Equal(t, args, execHook.ExecutedCommand.Args)
assertFlags(t, expectedFlags, execHook.ExecutedCommand)
Expand Down
35 changes: 18 additions & 17 deletions ignite/pkg/cosmosanalysis/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,58 @@ type Msgs map[string][]string
// Module keeps metadata about a Cosmos SDK module.
type Module struct {
// Name of the module.
Name string
Name string `json:"name,omitempty"`

// GoModulePath of the app where the module is defined.
GoModulePath string
GoModulePath string `json:"go_module_path,omitempty"`

// Pkg holds the proto package info.
Pkg protoanalysis.Package
Pkg protoanalysis.Package `json:"package,omitempty"`

// Msg is a list of sdk.Msg implementation of the module.
Msgs []Msg
Msgs []Msg `json:"messages,omitempty"`

// HTTPQueries is a list of module queries.
HTTPQueries []HTTPQuery
HTTPQueries []HTTPQuery `json:"http_queries,omitempty"`

// Types is a list of proto types that might be used by module.
Types []Type
Types []Type `json:"types,omitempty"`
}

// Msg keeps metadata about an sdk.Msg implementation.
type Msg struct {
// Name of the type.
Name string
Name string `json:"name,omitempty"`

// URI of the type.
URI string
URI string `json:"uri,omitempty"`

// FilePath is the path of the .proto file where message is defined at.
FilePath string
// File path is the path of the proto file where message is defined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go's documentation standard:

Suggested change
// File path is the path of the proto file where message is defined.
// FilePath is the path of the proto file where message is defined.

FilePath string `json:"file_path,omitempty"`
}

// HTTPQuery is an sdk Query.
type HTTPQuery struct {
// Name of the RPC func.
Name string
Name string `json:"name,omitempty"`

// FullName of the query with service name and rpc func name.
FullName string
FullName string `json:"full_name,omitempty"`

// HTTPAnnotations keeps info about http annotations of query.
Rules []protoanalysis.HTTPRule
Rules []protoanalysis.HTTPRule `json:"rules,omitempty"`

// Paginated indicates that the query is using pagination.
Paginated bool
Paginated bool `json:"paginated,omitempty"`
}

// Type is a proto type that might be used by module.
type Type struct {
Name string
// Name pf the type.
Name string `json:"name,omitempty"`

// FilePath is the path of the .proto file where message is defined at.
FilePath string
// File path is the path of the .proto file where message is defined at.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// File path is the path of the .proto file where message is defined at.
// FilePath is the path of the .proto file where message is defined at.

FilePath string `json:"file_path,omitempty"`
}

type moduleDiscoverer struct {
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosclient/mocks/account_retriever.go

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

2 changes: 1 addition & 1 deletion ignite/pkg/cosmosclient/mocks/bank_query_client.go

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

12 changes: 10 additions & 2 deletions ignite/pkg/cosmosclient/mocks/faucet_client.go

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

14 changes: 11 additions & 3 deletions ignite/pkg/cosmosclient/mocks/gasometer.go

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

2 changes: 1 addition & 1 deletion ignite/pkg/cosmosclient/mocks/rpc_client.go

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

7 changes: 6 additions & 1 deletion ignite/pkg/cosmosclient/mocks/signer.go

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

2 changes: 1 addition & 1 deletion ignite/pkg/cosmosgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
}

// Read the dependencies defined in the `go.mod` file
g.deps, err = gomodule.ResolveDependencies(modFile)
g.deps, err = gomodule.ResolveDependencies(modFile, false)
if err != nil {
return err
}

Check warning on line 65 in ignite/pkg/cosmosgen/generate.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/cosmosgen/generate.go#L62-L65

Added lines #L62 - L65 were not covered by tests

// Discover any custom modules defined by the user's app
g.appModules, err = g.discoverModules(g.appPath, g.protoDir)
Expand Down
10 changes: 7 additions & 3 deletions ignite/pkg/cosmostxcollector/mocks/saver.go

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

Loading
Loading