diff --git a/changelog.md b/changelog.md index 733312c949..409acd8ec6 100644 --- a/changelog.md +++ b/changelog.md @@ -31,6 +31,7 @@ - [#4008](https://github.com/ignite/cli/pull/4008) Rename `pkg/yaml` to `pkg/xyaml` - [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2` - [#4103](https://github.com/ignite/cli/pull/4103) Bump cosmos-sdk to `v0.50.6` +- [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure. ### Fixes diff --git a/ignite/services/scaffolder/configs.go b/ignite/services/scaffolder/configs.go index 05b3fab530..40c35d7e03 100644 --- a/ignite/services/scaffolder/configs.go +++ b/ignite/services/scaffolder/configs.go @@ -52,6 +52,7 @@ func (s Scaffolder) CreateConfigs( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. } g, err := modulecreate.NewModuleConfigs(opts) diff --git a/ignite/services/scaffolder/init.go b/ignite/services/scaffolder/init.go index 7eda0b7e1a..76270b6da9 100644 --- a/ignite/services/scaffolder/init.go +++ b/ignite/services/scaffolder/init.go @@ -126,6 +126,7 @@ func generate( AppName: pathInfo.Package, AppPath: absRoot, ProtoDir: protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. Params: paramsFields, Configs: configsFields, IsIBC: false, diff --git a/ignite/services/scaffolder/message.go b/ignite/services/scaffolder/message.go index 96583abaa6..a2c6398054 100644 --- a/ignite/services/scaffolder/message.go +++ b/ignite/services/scaffolder/message.go @@ -130,6 +130,7 @@ func (s Scaffolder) AddMessage( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. ModulePath: s.modpath.RawPath, ModuleName: moduleName, MsgName: name, @@ -153,6 +154,7 @@ func (s Scaffolder) AddMessage( AppName: opts.AppName, AppPath: opts.AppPath, ProtoDir: opts.ProtoDir, + ProtoVer: opts.ProtoVer, }, ) if err != nil { diff --git a/ignite/services/scaffolder/module.go b/ignite/services/scaffolder/module.go index f3ff25df59..55b756d03f 100644 --- a/ignite/services/scaffolder/module.go +++ b/ignite/services/scaffolder/module.go @@ -209,6 +209,7 @@ func (s Scaffolder) CreateModule( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. IsIBC: creationOpts.ibc, IBCOrdering: creationOpts.ibcChannelOrdering, Dependencies: creationOpts.dependencies, diff --git a/ignite/services/scaffolder/packet.go b/ignite/services/scaffolder/packet.go index c27fd0798a..ca270c85eb 100644 --- a/ignite/services/scaffolder/packet.go +++ b/ignite/services/scaffolder/packet.go @@ -122,6 +122,7 @@ func (s Scaffolder) AddPacket( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. ModulePath: s.modpath.RawPath, ModuleName: moduleName, PacketName: name, diff --git a/ignite/services/scaffolder/params.go b/ignite/services/scaffolder/params.go index 1a06260b21..d0edf64f4e 100644 --- a/ignite/services/scaffolder/params.go +++ b/ignite/services/scaffolder/params.go @@ -51,6 +51,7 @@ func (s Scaffolder) CreateParams( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. } g, err := modulecreate.NewModuleParam(opts) diff --git a/ignite/services/scaffolder/query.go b/ignite/services/scaffolder/query.go index 9584935868..7f3d5b6cbf 100644 --- a/ignite/services/scaffolder/query.go +++ b/ignite/services/scaffolder/query.go @@ -64,6 +64,7 @@ func (s Scaffolder) AddQuery( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. ModulePath: s.modpath.RawPath, ModuleName: moduleName, QueryName: name, diff --git a/ignite/services/scaffolder/type.go b/ignite/services/scaffolder/type.go index 6f8f50cb33..90765e1971 100644 --- a/ignite/services/scaffolder/type.go +++ b/ignite/services/scaffolder/type.go @@ -167,6 +167,7 @@ func (s Scaffolder) AddType( AppName: s.modpath.Package, AppPath: s.appPath, ProtoDir: s.protoDir, + ProtoVer: "v1", // TODO(@julienrbrt): possibly in the future add flag to specify custom proto version. ModulePath: s.modpath.RawPath, ModuleName: moduleName, TypeName: name, @@ -188,6 +189,8 @@ func (s Scaffolder) AddType( ModulePath: opts.ModulePath, AppName: opts.AppName, AppPath: opts.AppPath, + ProtoDir: opts.ProtoDir, + ProtoVer: opts.ProtoVer, }, ) if err != nil { diff --git a/ignite/templates/ibc/packet.go b/ignite/templates/ibc/packet.go index b2f99b83b7..9090fecb7a 100644 --- a/ignite/templates/ibc/packet.go +++ b/ignite/templates/ibc/packet.go @@ -35,6 +35,7 @@ type PacketOptions struct { AppName string AppPath string ProtoDir string + ProtoVer string ModuleName string ModulePath string PacketName multiformatname.Name @@ -44,6 +45,11 @@ type PacketOptions struct { NoMessage bool } +// ProtoFile returns the path to the proto folder +func (opts *PacketOptions) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} + // NewPacket returns the generator to scaffold a packet in an IBC module. func NewPacket(replacer placeholder.Replacer, opts *PacketOptions) (*genny.Generator, error) { var ( @@ -83,6 +89,7 @@ func NewPacket(replacer placeholder.Replacer, opts *PacketOptions) (*genny.Gener ctx.Set("moduleName", opts.ModuleName) ctx.Set("ModulePath", opts.ModulePath) ctx.Set("appName", opts.AppName) + ctx.Set("protoVer", opts.ProtoVer) ctx.Set("packetName", opts.PacketName) ctx.Set("MsgSigner", opts.MsgSigner) ctx.Set("fields", opts.Fields) @@ -93,6 +100,7 @@ func NewPacket(replacer placeholder.Replacer, opts *PacketOptions) (*genny.Gener g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) g.Transformer(genny.Replace("{{packetName}}", opts.PacketName.Snake)) // Create the 'testutil' package with the test helpers @@ -183,7 +191,7 @@ func moduleModify(replacer placeholder.Replacer, opts *PacketOptions) genny.RunF // - Existence of a Oneof field named 'packet'. func protoModify(opts *PacketOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "packet.proto") + path := opts.ProtoFile("packet.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -290,7 +298,7 @@ func eventModify(replacer placeholder.Replacer, opts *PacketOptions) genny.RunFn // elements in the file. func protoTxModify(opts *PacketOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "tx.proto") + path := opts.ProtoFile("tx.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/message/message.go b/ignite/templates/message/message.go index b394e02914..6f3f48a56f 100644 --- a/ignite/templates/message/message.go +++ b/ignite/templates/message/message.go @@ -34,6 +34,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { } ctx := plush.NewContext() ctx.Set("ModuleName", opts.ModuleName) + ctx.Set("ProtoVer", opts.ProtoVer) ctx.Set("AppName", opts.AppName) ctx.Set("MsgName", opts.MsgName) ctx.Set("MsgDesc", opts.MsgDesc) @@ -47,6 +48,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) g.Transformer(genny.Replace("{{msgName}}", opts.MsgName.Snake)) // Create the 'testutil' package with the test helpers @@ -88,7 +90,7 @@ func NewGenerator(replacer placeholder.Replacer, opts *Options) (*genny.Generato // - A service named "Msg" to exist in the proto file, it appends the RPCs inside it. func protoTxRPCModify(opts *Options) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "tx.proto") + path := opts.ProtoFile("tx.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -119,7 +121,7 @@ func protoTxRPCModify(opts *Options) genny.RunFn { func protoTxMessageModify(opts *Options) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "tx.proto") + path := opts.ProtoFile("tx.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/message/options.go b/ignite/templates/message/options.go index b8b00890bd..a922c067c4 100644 --- a/ignite/templates/message/options.go +++ b/ignite/templates/message/options.go @@ -1,6 +1,8 @@ package message import ( + "path/filepath" + "github.com/ignite/cli/v29/ignite/pkg/multiformatname" "github.com/ignite/cli/v29/ignite/templates/field" ) @@ -10,6 +12,7 @@ type Options struct { AppName string AppPath string ProtoDir string + ProtoVer string ModuleName string ModulePath string MsgName multiformatname.Name @@ -20,7 +23,7 @@ type Options struct { NoSimulation bool } -// Validate that options are usable. -func (opts *Options) Validate() error { - return nil +// ProtoFile returns the path to the proto folder +func (opts *Options) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) } diff --git a/ignite/templates/module/create/base.go b/ignite/templates/module/create/base.go index 79265fdbea..99a309b398 100644 --- a/ignite/templates/module/create/base.go +++ b/ignite/templates/module/create/base.go @@ -47,12 +47,13 @@ func NewGenerator(opts *CreateOptions) (*genny.Generator, error) { ctx.Set("moduleName", opts.ModuleName) ctx.Set("modulePath", opts.ModulePath) ctx.Set("appName", opts.AppName) + ctx.Set("protoVer", opts.ProtoVer) ctx.Set("dependencies", opts.Dependencies) ctx.Set("params", opts.Params) ctx.Set("configs", opts.Configs) ctx.Set("isIBC", opts.IsIBC) ctx.Set("apiPath", fmt.Sprintf("/%s/%s", appModulePath, opts.ModuleName)) - ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName)) + ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) ctx.Set("toVariableName", strcase.ToLowerCamel) plushhelpers.ExtendPlushContext(ctx) @@ -60,6 +61,7 @@ func NewGenerator(opts *CreateOptions) (*genny.Generator, error) { g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) return g, nil } @@ -88,7 +90,7 @@ func appConfigModify(replacer placeholder.Replacer, opts *CreateOptions) genny.R fConfig.String(), xast.WithLastNamedImport( fmt.Sprintf("%[1]vmodulev1", opts.ModuleName), - fmt.Sprintf("%[1]v/api/%[2]v/%[3]v/module", opts.ModulePath, opts.AppName, opts.ModuleName), + fmt.Sprintf("%[1]v/api/%[2]v/%[3]v/module/%[4]v", opts.ModulePath, opts.AppName, opts.ModuleName, opts.ProtoVer), ), xast.WithLastNamedImport( "_", diff --git a/ignite/templates/module/create/configs.go b/ignite/templates/module/create/configs.go index de74dace00..598ee789fc 100644 --- a/ignite/templates/module/create/configs.go +++ b/ignite/templates/module/create/configs.go @@ -1,8 +1,6 @@ package modulecreate import ( - "path/filepath" - "github.com/gobuffalo/genny/v2" "github.com/ignite/cli/v29/ignite/pkg/errors" @@ -18,7 +16,7 @@ func NewModuleConfigs(opts ConfigsOptions) (*genny.Generator, error) { func configsProtoModify(opts ConfigsOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "module/module.proto") + path := opts.ProtoFile("module/module.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/module/create/files/base/api/{{appName}}/{{moduleName}}/module/module.pulsar.go.plush b/ignite/templates/module/create/files/base/api/{{appName}}/{{moduleName}}/module/{{protoVer}}/module.pulsar.go.plush similarity index 100% rename from ignite/templates/module/create/files/base/api/{{appName}}/{{moduleName}}/module/module.pulsar.go.plush rename to ignite/templates/module/create/files/base/api/{{appName}}/{{moduleName}}/module/{{protoVer}}/module.pulsar.go.plush diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/autocli.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/autocli.go.plush index b6eb59d93a..4d15543c0b 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/autocli.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/autocli.go.plush @@ -3,7 +3,7 @@ package <%= moduleName %> import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - modulev1 "<%= modulePath %>/api/<%= appName %>/<%= moduleName %>" + modulev1 "<%= modulePath %>/api/<%= appName %>/<%= moduleName %>/<%= protoVer %>" ) // AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush index beed984303..a054e74c61 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/module/module.go.plush @@ -25,7 +25,7 @@ import ( // this line is used by starport scaffolding # 1 - modulev1 "<%= modulePath %>/api/<%= appName %>/<%= moduleName %>/module" + modulev1 "<%= modulePath %>/api/<%= appName %>/<%= moduleName %>/module/<%= protoVer %>" "<%= modulePath %>/x/<%= moduleName %>/keeper" "<%= modulePath %>/x/<%= moduleName %>/types" <%= if (isIBC) { %>"<%= modulePath %>/x/<%= moduleName %>/client/cli"<% } %> diff --git a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/module/module.proto.plush b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/module/{{protoVer}}/module.proto.plush similarity index 100% rename from ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/module/module.proto.plush rename to ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/module/{{protoVer}}/module.proto.plush diff --git a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/genesis.proto.plush b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/genesis.proto.plush similarity index 85% rename from ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/genesis.proto.plush rename to ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/genesis.proto.plush index 6d82a4f2fe..9094f5afed 100644 --- a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/genesis.proto.plush +++ b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/genesis.proto.plush @@ -3,7 +3,7 @@ package <%= protoPkgName %>; import "amino/amino.proto"; import "gogoproto/gogo.proto"; -import "<%= appName %>/<%= moduleName %>/params.proto"; +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/params.proto"; option go_package = "<%= modulePath %>/x/<%= moduleName %>/types"; diff --git a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/params.proto.plush b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/params.proto.plush similarity index 100% rename from ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/params.proto.plush rename to ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/params.proto.plush diff --git a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/query.proto.plush b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/query.proto.plush similarity index 92% rename from ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/query.proto.plush rename to ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/query.proto.plush index ab3548bce6..697f054d6b 100644 --- a/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/query.proto.plush +++ b/ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/query.proto.plush @@ -5,7 +5,7 @@ import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; -import "<%= appName %>/<%= moduleName %>/params.proto"; +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/params.proto"; option go_package = "<%= modulePath %>/x/<%= moduleName %>/types"; diff --git a/ignite/templates/module/create/files/ibc/{{protoDir}}/{{appName}}/{{moduleName}}/packet.proto.plush b/ignite/templates/module/create/files/ibc/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/packet.proto.plush similarity index 100% rename from ignite/templates/module/create/files/ibc/{{protoDir}}/{{appName}}/{{moduleName}}/packet.proto.plush rename to ignite/templates/module/create/files/ibc/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/packet.proto.plush diff --git a/ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/tx.proto.plush b/ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/tx.proto.plush similarity index 94% rename from ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/tx.proto.plush rename to ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/tx.proto.plush index 0d1df9db15..e8007f9145 100644 --- a/ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/tx.proto.plush +++ b/ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/tx.proto.plush @@ -5,7 +5,7 @@ import "amino/amino.proto"; import "cosmos/msg/v1/msg.proto"; import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; -import "<%= appName %>/<%= moduleName %>/params.proto"; +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/params.proto"; option go_package = "<%= modulePath %>/x/<%= moduleName %>/types"; diff --git a/ignite/templates/module/create/ibc.go b/ignite/templates/module/create/ibc.go index 28b5639cd0..2f3a42e44a 100644 --- a/ignite/templates/module/create/ibc.go +++ b/ignite/templates/module/create/ibc.go @@ -41,15 +41,18 @@ func NewIBC(replacer placeholder.Replacer, opts *CreateOptions) (*genny.Generato ctx.Set("moduleName", opts.ModuleName) ctx.Set("modulePath", opts.ModulePath) ctx.Set("appName", opts.AppName) + ctx.Set("protoVer", opts.ProtoVer) ctx.Set("ibcOrdering", opts.IBCOrdering) ctx.Set("dependencies", opts.Dependencies) - ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName)) + ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) plushhelpers.ExtendPlushContext(ctx) g.Transformer(xgenny.Transformer(ctx)) g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) + return g, nil } @@ -131,7 +134,7 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *CreateOptions) genn // - Existence of a message named 'GenesisState' in genesis.proto. func genesisProtoModify(opts *CreateOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "genesis.proto") + path := opts.ProtoFile("genesis.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/module/create/msgserver.go b/ignite/templates/module/create/msgserver.go index b3938e440f..d2e2b8a9f0 100644 --- a/ignite/templates/module/create/msgserver.go +++ b/ignite/templates/module/create/msgserver.go @@ -36,13 +36,16 @@ func AddMsgServerConventionToLegacyModule(replacer placeholder.Replacer, opts *M ctx.Set("moduleName", opts.ModuleName) ctx.Set("modulePath", opts.ModulePath) ctx.Set("appName", opts.AppName) - ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName)) + ctx.Set("protoVer", opts.ProtoVer) + ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) plushhelpers.ExtendPlushContext(ctx) g.Transformer(xgenny.Transformer(ctx)) g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) + return g, nil } diff --git a/ignite/templates/module/create/options.go b/ignite/templates/module/create/options.go index 3b93b0e876..629b37bad2 100644 --- a/ignite/templates/module/create/options.go +++ b/ignite/templates/module/create/options.go @@ -2,68 +2,91 @@ package modulecreate import ( "fmt" + "path/filepath" "github.com/iancoleman/strcase" "github.com/ignite/cli/v29/ignite/templates/field" ) -type ( - // ConfigsOptions represents the options to scaffold a Cosmos SDK module configs. - ConfigsOptions struct { - ModuleName string - AppName string - AppPath string - ProtoDir string - Configs field.Fields - } +// ConfigsOptions represents the options to scaffold a Cosmos SDK module configs. +type ConfigsOptions struct { + ModuleName string + AppName string + AppPath string + ProtoDir string + ProtoVer string + Configs field.Fields +} - // ParamsOptions represents the options to scaffold a Cosmos SDK module parameters. - ParamsOptions struct { - ModuleName string - AppName string - AppPath string - ProtoDir string - Params field.Fields - } +// ProtoFile returns the path to the proto folder +func (opts *ConfigsOptions) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} - // CreateOptions represents the options to scaffold a Cosmos SDK module. - CreateOptions struct { - ModuleName string - ModulePath string - AppName string - AppPath string - ProtoDir string - Params field.Fields - Configs field.Fields +// ParamsOptions represents the options to scaffold a Cosmos SDK module parameters. +type ParamsOptions struct { + ModuleName string + AppName string + AppPath string + ProtoDir string + ProtoVer string + Params field.Fields +} - // True if the module should implement the IBC module interface - IsIBC bool +// ProtoFile returns the path to the proto folder +func (opts *ParamsOptions) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} - // Channel ordering of the IBC module: ordered, unordered or none - IBCOrdering string +// MsgServerOptions defines options to add MsgServer. +type MsgServerOptions struct { + ModuleName string + ModulePath string + AppName string + AppPath string + ProtoDir string + ProtoVer string +} - // Dependencies of the module - Dependencies Dependencies - } +// ProtoFile returns the path to the proto folder +func (opts *MsgServerOptions) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} - // Dependency represents a module dependency of a module. - Dependency struct { - Name string - } +// CreateOptions represents the options to scaffold a Cosmos SDK module. +type CreateOptions struct { + ModuleName string + ModulePath string + AppName string + AppPath string + ProtoDir string + ProtoVer string + Params field.Fields + Configs field.Fields + + // True if the module should implement the IBC module interface + IsIBC bool + + // Channel ordering of the IBC module: ordered, unordered or none + IBCOrdering string + + // Dependencies of the module + Dependencies Dependencies +} + +// ProtoFile returns the path to the proto folder +func (opts *CreateOptions) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} - // Dependencies represents a list of module dependency. - Dependencies []Dependency +// Dependency represents a module dependency of a module. +type Dependency struct { + Name string +} - // MsgServerOptions defines options to add MsgServer. - MsgServerOptions struct { - ModuleName string - ModulePath string - AppName string - AppPath string - ProtoDir string - } -) +// Dependencies represents a list of module dependency. +type Dependencies []Dependency // NewDependency returns a new dependency. func NewDependency(name string) Dependency { diff --git a/ignite/templates/module/create/params.go b/ignite/templates/module/create/params.go index 475f5cd4e3..738ad993dc 100644 --- a/ignite/templates/module/create/params.go +++ b/ignite/templates/module/create/params.go @@ -21,7 +21,7 @@ func NewModuleParam(opts ParamsOptions) (*genny.Generator, error) { func paramsProtoModify(opts ParamsOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "params.proto") + path := opts.ProtoFile("params.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/module/module.go b/ignite/templates/module/module.go index 6059f2d0a9..f336336160 100644 --- a/ignite/templates/module/module.go +++ b/ignite/templates/module/module.go @@ -8,9 +8,15 @@ import ( ) // ProtoPackageName creates a protocol buffer package name for an app module. -func ProtoPackageName(appModulePath, moduleName string) string { +// When no version is provided, fallback to "v1". +func ProtoPackageName(appModulePath, moduleName, version string) string { + // good default + if version == "" { + version = "v1" + } + pathArray := strings.Split(appModulePath, "/") - path := []string{pathArray[len(pathArray)-1], moduleName} + path := []string{pathArray[len(pathArray)-1], moduleName, version} // Make sure that the first path element can be used as proto package name. // This is required for app module names like "github.com/username/repo" where diff --git a/ignite/templates/module/module_test.go b/ignite/templates/module/module_test.go index baa14a0bb0..7cae24cd7b 100644 --- a/ignite/templates/module/module_test.go +++ b/ignite/templates/module/module_test.go @@ -8,58 +8,73 @@ import ( func TestProtoPackageName(t *testing.T) { cases := []struct { - name string - app string - module string - want string + name string + app string + module string + version string + want string }{ { - name: "name", - app: "ignite", - module: "test", - want: "ignite.test", + name: "name", + app: "ignite", + module: "test", + version: "v1", + want: "ignite.test.v1", }, { - name: "path", - app: "ignite/cli", - module: "test", - want: "cli.test", + name: "name", + app: "ignite", + module: "test", + version: "v2", + want: "ignite.test.v2", }, { - name: "path with dash", - app: "ignite/c-li", - module: "test", - want: "cli.test", + name: "path", + app: "ignite/cli", + module: "test", + version: "v1", + want: "cli.test.v1", }, { - name: "path with number prefix", - app: "0ignite/cli", - module: "test", - want: "cli.test", + name: "path with dash", + app: "ignite/c-li", + module: "test", + version: "v1", + want: "cli.test.v1", }, { - name: "app with number prefix", - app: "ignite/0cli", - module: "test", - want: "_0cli.test", + name: "path with number prefix", + app: "0ignite/cli", + module: "test", + version: "v1", + want: "cli.test.v1", }, { - name: "path with number prefix and dash", - app: "0ignite/cli", - module: "test", - want: "cli.test", + name: "app with number prefix", + app: "ignite/0cli", + module: "test", + version: "v1", + want: "_0cli.test.v1", }, { - name: "module with dash", - app: "ignite", - module: "test-mod", - want: "ignite.testmod", + name: "path with number prefix and dash", + app: "0ignite/cli", + module: "test", + version: "v1", + want: "cli.test.v1", + }, + { + name: "module with dash", + app: "ignite", + module: "test-mod", + version: "v1", + want: "ignite.testmod.v1", }, } for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.want, ProtoPackageName(tt.app, tt.module)) + require.Equal(t, tt.want, ProtoPackageName(tt.app, tt.module, tt.version)) }) } } diff --git a/ignite/templates/query/options.go b/ignite/templates/query/options.go index 0ee7e1dd21..bb50125b50 100644 --- a/ignite/templates/query/options.go +++ b/ignite/templates/query/options.go @@ -1,6 +1,8 @@ package query import ( + "path/filepath" + "github.com/ignite/cli/v29/ignite/pkg/multiformatname" "github.com/ignite/cli/v29/ignite/templates/field" ) @@ -10,6 +12,7 @@ type Options struct { AppName string AppPath string ProtoDir string + ProtoVer string ModuleName string ModulePath string QueryName multiformatname.Name @@ -18,3 +21,8 @@ type Options struct { ReqFields field.Fields Paginated bool } + +// ProtoFile returns the path to the proto folder +func (opts *Options) ProtoFile(fname string) string { + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) +} diff --git a/ignite/templates/query/query.go b/ignite/templates/query/query.go index f9a5cb7906..e15811f889 100644 --- a/ignite/templates/query/query.go +++ b/ignite/templates/query/query.go @@ -29,6 +29,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { ctx := plush.NewContext() ctx.Set("ModuleName", opts.ModuleName) ctx.Set("AppName", opts.AppName) + ctx.Set("ProtoVer", opts.ProtoVer) ctx.Set("QueryName", opts.QueryName) ctx.Set("Description", opts.Description) ctx.Set("ModulePath", opts.ModulePath) @@ -41,6 +42,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) g.Transformer(genny.Replace("{{queryName}}", opts.QueryName.Snake)) return nil } @@ -68,7 +70,7 @@ func NewGenerator(replacer placeholder.Replacer, opts *Options) (*genny.Generato // - Existence of a service with name "Query" since that is where the RPCs will be added. func protoQueryModify(opts *Options) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "query.proto") + path := opts.ProtoFile("query.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush b/ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush similarity index 68% rename from ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush rename to ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush index ed24edd805..670a14f6f5 100644 --- a/ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush +++ b/ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush @@ -2,7 +2,7 @@ syntax = "proto3"; package <%= protoPkgName %>; option go_package = "<%= ModulePath %>/x/<%= ModuleName %>/types";<%= for (importName) in mergeCustomImports(Fields) { %> -import "<%= appName %>/<%= moduleName %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> import "<%= importName %>"; <% } %> message <%= TypeName.UpperCamel %> { diff --git a/ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush b/ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush similarity index 74% rename from ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush rename to ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush index 865ead96bc..1bdd6d60ca 100644 --- a/ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush +++ b/ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush @@ -2,7 +2,7 @@ syntax = "proto3"; package <%= protoPkgName %>; option go_package = "<%= ModulePath %>/x/<%= ModuleName %>/types";<%= for (importName) in mergeCustomImports(Fields) { %> -import "<%= AppName %>/<%= ModuleName %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> import "<%= importName %>"; <% } %> message <%= TypeName.UpperCamel %> { diff --git a/ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush b/ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush similarity index 78% rename from ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush rename to ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush index de089fbbe5..e6326182fc 100644 --- a/ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush +++ b/ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush @@ -2,7 +2,7 @@ syntax = "proto3"; package <%= protoPkgName %>; option go_package = "<%= ModulePath %>/x/<%= ModuleName %>/types";<%= for (importName) in mergeCustomImports(Fields, Indexes) { %> -import "<%= AppName %>/<%= ModuleName %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> import "<%= importName %>"; <% } %> message <%= TypeName.UpperCamel %> {<%= for (i, index) in Indexes { %> diff --git a/ignite/templates/typed/options.go b/ignite/templates/typed/options.go index 8c9877dcde..3649e305a3 100644 --- a/ignite/templates/typed/options.go +++ b/ignite/templates/typed/options.go @@ -16,6 +16,7 @@ type Options struct { AppName string AppPath string ProtoDir string + ProtoVer string ModuleName string ModulePath string TypeName multiformatname.Name @@ -34,10 +35,10 @@ func (opts *Options) Validate() error { // ProtoFile returns the path to the proto folder within the generated app. func (opts *Options) ProtoFile(fname string) string { - return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, fname) + return filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, opts.ProtoVer, fname) } // ProtoTypeImport Return the protobuf import statement for this type. func (opts *Options) ProtoTypeImport() *proto.Import { - return protoutil.NewImport(fmt.Sprintf("%s/%s/%s.proto", opts.AppName, opts.ModuleName, opts.TypeName.Snake)) + return protoutil.NewImport(fmt.Sprintf("%s/%s/%s/%s.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, opts.TypeName.Snake)) } diff --git a/ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush b/ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush similarity index 73% rename from ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush rename to ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush index 47a76f228f..1ad17f5c54 100644 --- a/ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{typeName}}.proto.plush +++ b/ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{{protoVer}}/{{typeName}}.proto.plush @@ -2,7 +2,7 @@ syntax = "proto3"; package <%= protoPkgName %>; option go_package = "<%= ModulePath %>/x/<%= ModuleName %>/types";<%= for (importName) in mergeCustomImports(Fields) { %> -import "<%= appName %>/<%= moduleName %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> +import "<%= appName %>/<%= moduleName %>/<%= protoVer %>/<%= importName %>.proto"; <% } %><%= for (importName) in mergeProtoImports(Fields) { %> import "<%= importName %>"; <% } %> message <%= TypeName.UpperCamel %> {<%= for (i, field) in Fields { %> diff --git a/ignite/templates/typed/typed.go b/ignite/templates/typed/typed.go index 51022e2b30..35be3f289c 100644 --- a/ignite/templates/typed/typed.go +++ b/ignite/templates/typed/typed.go @@ -21,6 +21,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { ctx := plush.NewContext() ctx.Set("ModuleName", opts.ModuleName) + ctx.Set("ProtoVer", opts.ProtoVer) ctx.Set("IsIBC", opts.IsIBC) ctx.Set("AppName", opts.AppName) ctx.Set("TypeName", opts.TypeName) @@ -29,7 +30,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { ctx.Set("Fields", opts.Fields) ctx.Set("Indexes", opts.Indexes) ctx.Set("NoMessage", opts.NoMessage) - ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName)) + ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) ctx.Set("strconv", func() bool { strconv := false for _, field := range opts.Fields { @@ -45,6 +46,7 @@ func Box(box packd.Walker, opts *Options, g *genny.Generator) error { g.Transformer(genny.Replace("{{protoDir}}", opts.ProtoDir)) g.Transformer(genny.Replace("{{appName}}", opts.AppName)) g.Transformer(genny.Replace("{{moduleName}}", opts.ModuleName)) + g.Transformer(genny.Replace("{{protoVer}}", opts.ProtoVer)) g.Transformer(genny.Replace("{{typeName}}", opts.TypeName.Snake)) // Create the 'testutil' package with the test helpers