Skip to content

Commit 0b2e0cf

Browse files
authored
fix: allow wiring of evolve module to wire an SDK chain without overriding the start command (#236)
* chore: added start flag to optionally disable addition of the start command * chore: attempt to register types chore: change abci version chore: corrected pseudo version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version chore: bump abci version * chore: add pre-blocker to template chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version chore: bump version * chore: reverted version change * chore: added changelog entry
1 parent 6bc5b70 commit 0b2e0cf

File tree

6 files changed

+70
-12
lines changed

6 files changed

+70
-12
lines changed

evolve/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- [#236](https://github.com/ignite/apps/pull/236) Add `--start` flag to `evolve add` command to optionally disable addition of the start command.
6+
57
## [`v0.4.3`](https://github.com/ignite/apps/releases/tag/evolve/v0.4.3)
68

79
- [#233](https://github.com/ignite/apps/pull/233) Bump dependencies.

evolve/cmd/add.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
statusScaffolding = "Scaffolding..."
1919

2020
flagPath = "path"
21+
flagStart = "start"
2122
flagMigrate = "migrate"
2223
)
2324

@@ -32,6 +33,11 @@ func AddHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
3233
return err
3334
}
3435

36+
withStartCmd, err := flags.GetBool(flagStart)
37+
if err != nil {
38+
return err
39+
}
40+
3541
migrateCometBFT, err := flags.GetBool(flagMigrate)
3642
if err != nil {
3743
return err
@@ -52,7 +58,7 @@ func AddHandler(ctx context.Context, cmd *plugin.ExecutedCommand) error {
5258
return err
5359
}
5460

55-
g, err := template.NewEvolveGenerator(c, migrateCometBFT)
61+
g, err := template.NewEvolveGenerator(c, migrateCometBFT, withStartCmd)
5662
if err != nil {
5763
return err
5864
}

evolve/cmd/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func GetCommands() []*plugin.Command {
2323
Shorthand: "p",
2424
Type: plugin.FlagTypeString,
2525
},
26+
{
27+
Name: flagStart,
28+
Usage: "modify start command to use ev-abci (set to false to only add migrate command)",
29+
Type: plugin.FlagTypeBool,
30+
DefaultValue: "true",
31+
},
2632
{
2733
Name: flagMigrate,
2834
Usage: "scaffolds the migrations helpers and modules (to use when migrating from CometBFT)",

evolve/template/generator.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// NewEvolveGenerator returns the generator to scaffold a evolve integration inside an app.
14-
func NewEvolveGenerator(chain *chain.Chain, withCometMigration bool) (*genny.Generator, error) {
14+
func NewEvolveGenerator(chain *chain.Chain, withCometMigration, withStartCmd bool) (*genny.Generator, error) {
1515
g := genny.New()
1616
ctx := plush.NewContext()
1717
plushhelpers.ExtendPlushContext(ctx)
@@ -28,9 +28,12 @@ func NewEvolveGenerator(chain *chain.Chain, withCometMigration bool) (*genny.Gen
2828
return nil, errors.Errorf("failed to update go.mod: %w", err)
2929
}
3030

31-
g.RunFn(commandsStartModify(appPath, binaryName, chain.Version))
32-
g.RunFn(commandsGenesisModify(appPath, binaryName))
33-
g.RunFn(commandsRollbackModify(appPath, binaryName))
31+
if withStartCmd {
32+
g.RunFn(commandsStartModify(appPath, binaryName, chain.Version))
33+
g.RunFn(commandsGenesisInitModify(appPath, binaryName))
34+
g.RunFn(commandsRollbackModify(appPath, binaryName))
35+
}
36+
g.RunFn(commandsMigrateModify(appPath, binaryName))
3437
if withCometMigration {
3538
g.RunFn(migrateFromCometModify(appPath))
3639
}

evolve/template/init.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ func commandsStartModify(appPath, binaryName string, version cosmosver.Version)
7171
}
7272
}
7373

74-
// commandsGenesisModify modifies the application genesis command to use evolve.
75-
func commandsGenesisModify(appPath, binaryName string) genny.RunFn {
74+
// commandsGenesisInitModify modifies the application genesis init command to use evolve.
75+
// this is only needed when the start command is also modified.
76+
func commandsGenesisInitModify(appPath, binaryName string) genny.RunFn {
7677
return func(r *genny.Runner) error {
7778
cmdPath := filepath.Join(appPath, "cmd", binaryName, "cmd/commands.go")
7879
f, err := r.Disk.Find(cmdPath)
@@ -109,13 +110,38 @@ func commandsGenesisModify(appPath, binaryName string) genny.RunFn {
109110
}
110111

111112
// modify the add commands arguments using xast.
112-
alreadyAdded := false // to avoid adding the migrate command multiple times as there are multiple calls to `rootCmd.AddCommand`
113113
content, err = xast.ModifyCaller(content, "rootCmd.AddCommand", func(args []string) ([]string, error) {
114114
if strings.Contains(args[0], "InitCmd") {
115115
args[0] = "genesisCmd"
116116
}
117117

118-
// add migrate command
118+
return args, nil
119+
})
120+
121+
return r.File(genny.NewFileS(cmdPath, content))
122+
}
123+
}
124+
125+
// commandsMigrateModify adds the evolve migrate command to the application.
126+
func commandsMigrateModify(appPath, binaryName string) genny.RunFn {
127+
return func(r *genny.Runner) error {
128+
cmdPath := filepath.Join(appPath, "cmd", binaryName, "cmd/commands.go")
129+
f, err := r.Disk.Find(cmdPath)
130+
if err != nil {
131+
return err
132+
}
133+
134+
content, err := xast.AppendImports(
135+
f.String(),
136+
xast.WithNamedImport("abciserver", "github.com/evstack/ev-abci/server"),
137+
)
138+
if err != nil {
139+
return err
140+
}
141+
142+
// add migrate command
143+
alreadyAdded := false // to avoid adding the migrate command multiple times as there are multiple calls to `rootCmd.AddCommand`
144+
content, err = xast.ModifyCaller(content, "rootCmd.AddCommand", func(args []string) ([]string, error) {
119145
if !alreadyAdded {
120146
args = append(args, evolveV1MigrateCmd)
121147
alreadyAdded = true

evolve/template/migrate.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,26 @@ func migrateFromCometModify(appPath string) genny.RunFn {
3333
return err
3434
}
3535

36+
// add migrationmngr module config for depinject
37+
moduleConfigTemplate := `{
38+
Name: migrationmngrtypes.ModuleName,
39+
Config: appconfig.WrapAny(&migrationmngrmodule.Module{}),
40+
},
41+
%[1]v`
42+
moduleConfigReplacement := fmt.Sprintf(moduleConfigTemplate, module.PlaceholderSgAppModuleConfig)
43+
content = replacer.Replace(content, module.PlaceholderSgAppModuleConfig, moduleConfigReplacement)
44+
45+
// preblocker for migrationmngr
46+
preBlockerTemplate := `migrationmngrtypes.ModuleName,
47+
%[1]v`
48+
preBlockerReplacement := fmt.Sprintf(preBlockerTemplate, "// this line is used by starport scaffolding # stargate/app/preBlockers")
49+
content = replacer.Replace(content, "// this line is used by starport scaffolding # stargate/app/preBlockers", preBlockerReplacement)
50+
3651
// end block for migrationmngr
37-
template := `migrationmngrtypes.ModuleName,
52+
endBlockerTemplate := `migrationmngrtypes.ModuleName,
3853
%[1]v`
39-
replacement := fmt.Sprintf(template, module.PlaceholderSgAppEndBlockers)
40-
content = replacer.Replace(content, module.PlaceholderSgAppEndBlockers, replacement)
54+
endBlockerReplacement := fmt.Sprintf(endBlockerTemplate, module.PlaceholderSgAppEndBlockers)
55+
content = replacer.Replace(content, module.PlaceholderSgAppEndBlockers, endBlockerReplacement)
4156

4257
// replace staking blank import
4358
content = strings.Replace(content, "github.com/cosmos/cosmos-sdk/x/staking", "github.com/evstack/ev-abci/modules/staking", 1)

0 commit comments

Comments
 (0)