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 5 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
9 changes: 5 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

## Unreleased

### Fixes

- [#3825](https://github.com/ignite/cli/pull/3825) Fix a minor Keplr type-checking bug in TS client

### Features

- [#3830](https://github.com/ignite/cli/pull/3830) Remove gRPC info from Ignite Apps errors
- [#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

- [#3825](https://github.com/ignite/cli/pull/3825) Fix a minor Keplr type-checking bug in TS client

## [`v28.0.0`](https://github.com/ignite/cli/releases/tag/v28.0.0)

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 @@ -11,6 +11,7 @@ import (
)

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

Expand Down Expand Up @@ -81,6 +82,7 @@ about Cosmos SDK on https://docs.cosmos.network
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)")

return c
}
Expand All @@ -95,6 +97,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
appPath = flagGetPath(cmd)
noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule)
skipGit, _ = cmd.Flags().GetBool(flagSkipGit)
minimal, _ = cmd.Flags().GetBool(flagMinimal)
)

params, err := cmd.Flags().GetStringSlice(flagParams)
Expand All @@ -119,6 +122,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
addressPrefix,
noDefaultModule,
skipGit,
minimal,
params,
)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions ignite/cmd/scaffold_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,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
}
var moduleNameKeeperAlias = map[string]string{}

const (
flagDep = "dep"
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 @@ type Config struct {
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
}

// 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 @@ func PackageLiteral(path, version string) string {
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})
}

// 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 @@ func Init(
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 @@ func Init(
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)
if err != nil {
return "", err
}
Expand All @@ -73,7 +73,7 @@ func generate(
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 @@ func generate(
GitHubPath: githubPath,
BinaryNamePrefix: pathInfo.Root,
AddressPrefix: addressPrefix,
IsChainMinimal: minimal,
})
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions ignite/services/scaffolder/scaffolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ func finish(ctx context.Context, cacheStorage cache.Storage, path, gomodPath str
return err
}

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

if err := gocmd.GoImports(ctx, path); err != nil {
return err
}

return gocmd.ModTidy(ctx, path)
}

func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodPath string) error {
Expand Down
28 changes: 27 additions & 1 deletion ignite/templates/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import (
//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 +30,36 @@ func NewGenerator(opts *Options) (*genny.Generator, error) {
return nil, fmt.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)
}

if err := g.SelectiveFS(subfs, opts.IncludePrefixes, nil, excludePrefix, nil); err != nil {
return g, fmt.Errorf("generator fs: %w", err)
}

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

g.File(genny.NewFile(appConfig, file))
}
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

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)

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