Skip to content

Commit 8fc47a1

Browse files
authored
feat: introduce gnovm app (#238)
* feat: introduce gnovm app * chore: use tag
1 parent b933f38 commit 8fc47a1

File tree

15 files changed

+2059
-0
lines changed

15 files changed

+2059
-0
lines changed

_registry/ignite.apps.gnovm.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"appName": "GnoVM",
3+
"appID": "gnovm",
4+
"appDescription": "Scaffold a Cosmos GnoVM-enabled chain with ease",
5+
"ignite": ">29.5.0",
6+
"dependencies": {},
7+
"cosmosSDK": ">0.50.1",
8+
"authors": [
9+
{
10+
"name": "Julien Robert",
11+
"github": "julienrbrt"
12+
}
13+
],
14+
"repositoryUrl": "https://github.com/ignite/apps/gnovm",
15+
"documentationUrl": "https://github.com/ignite/apps/tree/main/gnovm/README.md",
16+
"license": {
17+
"name": "MIT",
18+
"url": "https://github.com/ignite/apps/blob/main/LICENSE"
19+
},
20+
"keywords": [
21+
"gnovm",
22+
"gnolang",
23+
"gno.land",
24+
"cli",
25+
"cosmos-sdk",
26+
"ignite app",
27+
"cosmos"
28+
],
29+
"supportedPlatforms": ["mac", "linux"]
30+
}

app.ignite.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ apps:
5454
example-hooks:
5555
description: A simple hooks application
5656
path: ./examples/hooks
57+
gnovm:
58+
description: Scaffold a GnoVM-enabled chain with ease
59+
path: ./gnovm

gnovm/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# GnoVM App Changelog
2+
3+
## [`v0.1.0`](https://github.com/ignite/apps/releases/tag/gnovm/v0.1.0)
4+
5+
- First release of the GnoVM app compatible with Ignite >= v29.5.0

gnovm/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# GnoVM
2+
3+
This Ignite App is aimed to extend [Ignite CLI](https://github.com/ignite/cli) and bootstrap the development of an [GnoVM](https://github.com/gnolang/gno)-enabled Cosmos SDK blockchain.
4+
5+
It uses the [GnoVM](https://github.com/ignite/gnovm) Cosmos SDK module to do so.
6+
7+
## Prerequisites
8+
9+
- Ignite CLI version v29.5.0 or greater (no minimal chain).
10+
- Knowledge of blockchain development (Cosmos SDK).
11+
12+
## Usage
13+
14+
```sh
15+
ignite s chain gm --address-prefix gm --no-module
16+
cd gm
17+
ignite app install -g github.com/ignite/apps/gnovm
18+
ignite gnovm add
19+
```

gnovm/cmd/add.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"path/filepath"
6+
7+
"github.com/ignite/cli/v29/ignite/pkg/cliui"
8+
"github.com/ignite/cli/v29/ignite/pkg/cosmosver"
9+
"github.com/ignite/cli/v29/ignite/pkg/errors"
10+
"github.com/ignite/cli/v29/ignite/pkg/gocmd"
11+
"github.com/ignite/cli/v29/ignite/pkg/xgenny"
12+
"github.com/ignite/cli/v29/ignite/services/chain"
13+
"github.com/ignite/cli/v29/ignite/services/plugin"
14+
15+
"github.com/ignite/apps/gnovm/template"
16+
)
17+
18+
const (
19+
statusScaffolding = "Scaffolding..."
20+
21+
flagPath = "path"
22+
)
23+
24+
// AddHandler implements the GnoVM integration command
25+
func AddHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
26+
flags := plugin.Flags(cmd.Flags)
27+
28+
session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding))
29+
defer session.End()
30+
31+
appPath, err := flags.GetString(flagPath)
32+
if err != nil {
33+
return err
34+
}
35+
36+
absPath, err := filepath.Abs(appPath)
37+
if err != nil {
38+
return err
39+
}
40+
41+
c, err := chain.New(absPath, chain.CollectEvents(session.EventBus()))
42+
if err != nil {
43+
return err
44+
}
45+
46+
if c.Version.LT(cosmosver.StargateFiftyVersion) {
47+
return errors.New("GnoVM App requires Ignite v28+ / Cosmos SDK v0.50+")
48+
}
49+
50+
g, err := template.NewGnoVMGenerator(c)
51+
if err != nil {
52+
return err
53+
}
54+
55+
_, err = xgenny.NewRunner(ctx, appPath).RunAndApply(g)
56+
if err != nil {
57+
return err
58+
}
59+
60+
if finish(ctx, session, c.AppPath()) != nil {
61+
return err
62+
}
63+
64+
return session.Printf("🎉 GnoVM integration added (`%[1]v`).\n", c.AppPath(), c.Name())
65+
}
66+
67+
// finish finalize the scaffolded code (formating, dependencies).
68+
func finish(ctx context.Context, session *cliui.Session, path string) error {
69+
session.StopSpinner()
70+
session.StartSpinner("go mod tidy...")
71+
if err := gocmd.ModTidy(ctx, path); err != nil {
72+
return err
73+
}
74+
75+
session.StopSpinner()
76+
session.StartSpinner("Formatting code...")
77+
if err := gocmd.Fmt(ctx, path); err != nil {
78+
return err
79+
}
80+
81+
_ = gocmd.GoImports(ctx, path) // goimports installation could fail, so ignore the error
82+
83+
return nil
84+
}

gnovm/cmd/cmd.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cmd
2+
3+
import (
4+
"github.com/ignite/cli/v29/ignite/services/plugin"
5+
)
6+
7+
// GetCommands returns the list of app commands.
8+
func GetCommands() []*plugin.Command {
9+
return []*plugin.Command{
10+
{
11+
Use: "gnovm [command]",
12+
Aliases: []string{"gno"},
13+
Short: "Ignite GnoVM integration",
14+
Commands: []*plugin.Command{
15+
{
16+
Use: "add",
17+
Short: "Add GnoVM support",
18+
Long: "Add GnoVM support to your Cosmos SDK chain",
19+
Flags: []*plugin.Flag{
20+
{
21+
Name: flagPath,
22+
Usage: "path of the app",
23+
Shorthand: "p",
24+
Type: plugin.FlagTypeString,
25+
},
26+
},
27+
},
28+
},
29+
},
30+
}
31+
}

0 commit comments

Comments
 (0)