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

feat: scaffold minimal chain #3835

Merged
merged 24 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bb574cb
feat: scaffold minimal chain
julienrbrt Dec 9, 2023
74ef5d2
Merge branch 'main' into julien/minimal
julienrbrt Dec 9, 2023
8b1a75e
add changelog
julienrbrt Dec 9, 2023
7f82de2
updates
julienrbrt Dec 9, 2023
0787562
updates
julienrbrt Dec 9, 2023
50d5afa
update tests
julienrbrt Dec 11, 2023
dd1722a
Merge branch 'main' into julien/minimal
julienrbrt Dec 18, 2023
d0428d0
feedback
julienrbrt Dec 18, 2023
3b54e51
Merge branch 'main' into julien/minimal
julienrbrt Dec 20, 2023
73115d4
lint, scope better pr, add regression test
julienrbrt Dec 20, 2023
9a7e218
Merge branch 'main' into julien/minimal
julienrbrt Dec 20, 2023
bd4912b
update changelog
julienrbrt Dec 20, 2023
b35813e
Merge branch 'main' into julien/minimal
julienrbrt Dec 20, 2023
1f12174
Merge branch 'main' into julien/minimal
julienrbrt Dec 21, 2023
57d58f3
Merge branch 'main' into julien/minimal
julienrbrt Jan 8, 2024
c6c62cc
Merge branch 'main' into julien/minimal
julienrbrt Jan 11, 2024
8d9c63e
Merge branch 'main' into julien/minimal
julienrbrt Jan 11, 2024
078af48
Merge branch 'main' into julien/minimal
julienrbrt Jan 12, 2024
06717b8
Merge branch 'main' into julien/minimal
julienrbrt Jan 13, 2024
bf777dc
Merge branch 'main' into julien/minimal
julienrbrt Jan 14, 2024
825cba8
Merge branch 'main' into julien/minimal
julienrbrt Jan 15, 2024
0f4031b
Merge branch 'main' into julien/minimal
julienrbrt Jan 16, 2024
b1ead06
Merge branch 'main' into julien/minimal
julienrbrt Jan 16, 2024
68450ef
Merge branch 'main' into julien/minimal
julienrbrt Jan 16, 2024
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- [#3835](https://github.com/ignite/cli/pull/3835) Add `--minimal` flag to `scaffold chain` to scaffold a chain with the least amount of sdk modules

### Fixes

- [#3878](https://github.com/ignite/cli/pull/3878) Support local forks of Cosmos SDK in scaffolded chain.
Expand Down
4 changes: 4 additions & 0 deletions ignite/cmd/scaffold_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)

const (
flagMinimal = "minimal"
flagNoDefaultModule = "no-module"
flagSkipGit = "skip-git"

Expand Down Expand Up @@ -80,6 +81,7 @@
c.Flags().Bool(flagNoDefaultModule, false, "create a project without a default module")
c.Flags().StringSlice(flagParams, []string{}, "add default module parameters")
c.Flags().Bool(flagSkipGit, false, "skip Git repository initialization")
c.Flags().Bool(flagMinimal, false, "create a minimal blockchain (with the minimum required Cosmos SDK modules)")

Check warning on line 84 in ignite/cmd/scaffold_chain.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/scaffold_chain.go#L84

Added line #L84 was not covered by tests

return c
}
Expand All @@ -94,6 +96,7 @@
appPath = flagGetPath(cmd)
noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule)
skipGit, _ = cmd.Flags().GetBool(flagSkipGit)
minimal, _ = cmd.Flags().GetBool(flagMinimal)

Check warning on line 99 in ignite/cmd/scaffold_chain.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/scaffold_chain.go#L99

Added line #L99 was not covered by tests
)

params, err := cmd.Flags().GetStringSlice(flagParams)
Expand All @@ -118,6 +121,7 @@
addressPrefix,
noDefaultModule,
skipGit,
minimal,

Check warning on line 124 in ignite/cmd/scaffold_chain.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/scaffold_chain.go#L124

Added line #L124 was not covered by tests
params,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// moduleNameKeeperAlias is a map of well known module names that have a different keeper name than the usual <module-name>Keeper.
var moduleNameKeeperAlias = map[string]string{
"auth": "account",
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
"auth": "account", // TODO(@julienrbrt) remove this when x/accounts is released
}

const (
Expand Down
6 changes: 6 additions & 0 deletions ignite/config/chain/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,19 @@
Faucet Faucet `yaml:"faucet,omitempty"`
Client Client `yaml:"client,omitempty"`
Genesis xyaml.Map `yaml:"genesis,omitempty"`
Minimal bool `yaml:"minimal,omitempty"`
}

// GetVersion returns the config version.
func (c Config) GetVersion() version.Version {
return c.Version
}

// IsChainMinimal returns true if the chain is minimally scaffolded.
func (c Config) IsChainMinimal() bool {
return c.Minimal

Check warning on line 172 in ignite/config/chain/base/config.go

View check run for this annotation

Codecov / codecov/patch

ignite/config/chain/base/config.go#L171-L172

Added lines #L171 - L172 were not covered by tests
}

// SetDefaults assigns default values to empty config fields.
func (c *Config) SetDefaults() error {
return mergo.Merge(c, DefaultConfig())
Expand Down
5 changes: 5 additions & 0 deletions ignite/pkg/cosmosgen/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func DepTools() []string {
// grpc-gateway plugins.
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway",
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2",

// goimports
"golang.org/x/tools/cmd/goimports",
}
}

Expand All @@ -32,10 +35,12 @@ func InstallDepTools(ctx context.Context, appPath string) error {
if err := gocmd.ModTidy(ctx, appPath); err != nil {
return err
}

err := gocmd.Install(ctx, appPath, DepTools())
if gocmd.IsInstallError(err) {
return errors.New("unable to install dependency tools, run `ignite doctor` and try again")
}

return err
}

Expand Down
5 changes: 5 additions & 0 deletions ignite/pkg/gocmd/gocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
return fmt.Sprintf("%s@%s", path, version)
}

// Imports runs goimports on path with options.
func GoImports(ctx context.Context, path string) error {
return exec.Exec(ctx, []string{"goimports", "-w", path})

Check warning on line 234 in ignite/pkg/gocmd/gocmd.go

View check run for this annotation

Codecov / codecov/patch

ignite/pkg/gocmd/gocmd.go#L233-L234

Added lines #L233 - L234 were not covered by tests
}

// binaryPath determines the path where binary will be located at.
func binaryPath(output, binary string) (string, error) {
if output != "" {
Expand Down
7 changes: 4 additions & 3 deletions ignite/services/scaffolder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
cacheStorage cache.Storage,
tracer *placeholder.Tracer,
root, name, addressPrefix string,
noDefaultModule, skipGit bool,
noDefaultModule, skipGit, minimal bool,
params []string,
) (path string, err error) {
pathInfo, err := gomodulepath.Parse(name)
Expand All @@ -46,7 +46,7 @@
path = filepath.Join(root, appFolder)

// create the project
err = generate(ctx, tracer, pathInfo, addressPrefix, path, noDefaultModule, params)
err = generate(ctx, tracer, pathInfo, addressPrefix, path, noDefaultModule, minimal, params)

Check warning on line 49 in ignite/services/scaffolder/init.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/scaffolder/init.go#L49

Added line #L49 was not covered by tests
if err != nil {
return "", err
}
Expand All @@ -73,7 +73,7 @@
pathInfo gomodulepath.Path,
addressPrefix,
absRoot string,
noDefaultModule bool,
noDefaultModule, minimal bool,
params []string,
) error {
// Parse params with the associated type
Expand All @@ -96,6 +96,7 @@
GitHubPath: githubPath,
BinaryNamePrefix: pathInfo.Root,
AddressPrefix: addressPrefix,
IsChainMinimal: minimal,

Check warning on line 99 in ignite/services/scaffolder/init.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/scaffolder/init.go#L99

Added line #L99 was not covered by tests
})
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@
return err
}

if err := gocmd.ModTidy(ctx, path); err != nil {
if err := gocmd.Fmt(ctx, path); err != nil {

Check warning on line 72 in ignite/services/scaffolder/scaffolder.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/scaffolder/scaffolder.go#L72

Added line #L72 was not covered by tests
return err
}
return gocmd.Fmt(ctx, path)

_ = gocmd.GoImports(ctx, path) // goimports installation could fail, so ignore the error

return gocmd.ModTidy(ctx, path)

Check warning on line 78 in ignite/services/scaffolder/scaffolder.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/scaffolder/scaffolder.go#L76-L78

Added lines #L76 - L78 were not covered by tests
}

func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodPath string) error {
Expand Down
29 changes: 28 additions & 1 deletion ignite/templates/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"embed"
"fmt"
"io/fs"

"github.com/gobuffalo/genny/v2"
Expand All @@ -16,6 +17,12 @@
//go:embed files/* files/**/*
var files embed.FS

var (
ibcConfig = "app/ibc.go"
minimalAppConfig = "app/app_config_minimal.go"
appConfig = "app/app_config.go"
)

// NewGenerator returns the generator to scaffold a new Cosmos SDK app.
func NewGenerator(opts *Options) (*genny.Generator, error) {
// Remove "files/" prefix
Expand All @@ -24,16 +31,36 @@
return nil, errors.Errorf("generator sub: %w", err)
}
g := genny.New()
if err := g.OnlyFS(subfs, opts.IncludePrefixes, nil); err != nil {

// always exclude minimal app config it will be created later
// app_config_minimal is only used for the minimal app template
excludePrefix := []string{minimalAppConfig}
if opts.IsChainMinimal {
// minimal chain does not have ibc or classic app config
excludePrefix = append(excludePrefix, ibcConfig, appConfig)
}

Check warning on line 41 in ignite/templates/app/app.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/app/app.go#L34-L41

Added lines #L34 - L41 were not covered by tests

if err := g.SelectiveFS(subfs, opts.IncludePrefixes, nil, excludePrefix, nil); err != nil {

Check warning on line 43 in ignite/templates/app/app.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/app/app.go#L43

Added line #L43 was not covered by tests
return g, errors.Errorf("generator fs: %w", err)
}

if opts.IsChainMinimal {
file, err := subfs.Open(fmt.Sprintf("%s.plush", minimalAppConfig))
if err != nil {
return g, errors.Errorf("open minimal app config: %w", err)
}

Check warning on line 51 in ignite/templates/app/app.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/app/app.go#L47-L51

Added lines #L47 - L51 were not covered by tests

g.File(genny.NewFile(appConfig, file))

Check warning on line 53 in ignite/templates/app/app.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/app/app.go#L53

Added line #L53 was not covered by tests
}

ctx := plush.NewContext()
ctx.Set("ModulePath", opts.ModulePath)
ctx.Set("AppName", opts.AppName)
ctx.Set("GitHubPath", opts.GitHubPath)
ctx.Set("BinaryNamePrefix", opts.BinaryNamePrefix)
ctx.Set("AddressPrefix", opts.AddressPrefix)
ctx.Set("DepTools", cosmosgen.DepTools())
ctx.Set("IsChainMinimal", opts.IsChainMinimal)

Check warning on line 63 in ignite/templates/app/app.go

View check run for this annotation

Codecov / codecov/patch

ignite/templates/app/app.go#L63

Added line #L63 was not covered by tests

plushhelpers.ExtendPlushContext(ctx)
g.Transformer(xgenny.Transformer(ctx))
Expand Down
Loading
Loading