From 711cac2a337c1290610c296e1299fd6911644971 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 13 May 2024 23:33:23 +0200 Subject: [PATCH] refactor!: version scaffolded protos (#4118) --- changelog.md | 1 + ignite/services/scaffolder/configs.go | 1 + ignite/services/scaffolder/init.go | 1 + ignite/services/scaffolder/message.go | 3 +- ignite/services/scaffolder/module.go | 1 + ignite/services/scaffolder/packet.go | 1 + ignite/services/scaffolder/params.go | 1 + ignite/services/scaffolder/patch.go | 7 +- ignite/services/scaffolder/query.go | 1 + ignite/services/scaffolder/type.go | 4 +- ignite/templates/app/options.go | 5 - ignite/templates/ibc/packet.go | 18 ++- ignite/templates/message/message.go | 8 +- ignite/templates/message/options.go | 9 +- ignite/templates/module/create/base.go | 9 +- ignite/templates/module/create/configs.go | 3 +- .../{ => {{protoVer}}}/module.pulsar.go.plush | 0 .../x/{{moduleName}}/module/autocli.go.plush | 2 +- .../x/{{moduleName}}/module/module.go.plush | 2 +- .../{ => {{protoVer}}}/module.proto.plush | 2 +- .../{ => {{protoVer}}}/genesis.proto.plush | 2 +- .../{ => {{protoVer}}}/params.proto.plush | 0 .../{ => {{protoVer}}}/query.proto.plush | 2 +- .../{ => {{protoVer}}}/packet.proto.plush | 0 .../{ => {{protoVer}}}/tx.proto.plush | 2 +- ignite/templates/module/create/ibc.go | 7 +- ignite/templates/module/create/msgserver.go | 5 +- ignite/templates/module/create/options.go | 124 ++++++++++-------- ignite/templates/module/create/params.go | 2 +- ignite/templates/module/module.go | 17 ++- ignite/templates/module/module_test.go | 112 +++++++++++----- ignite/templates/query/options.go | 8 ++ ignite/templates/query/query.go | 8 +- .../{{typeName}}.proto.plush | 2 +- .../{{typeName}}.proto.plush | 2 +- ignite/templates/typed/list/list.go | 2 +- .../{{typeName}}.proto.plush | 2 +- ignite/templates/typed/map/map.go | 4 +- ignite/templates/typed/options.go | 10 +- .../{{typeName}}.proto.plush | 2 +- ignite/templates/typed/singleton/singleton.go | 2 +- ignite/templates/typed/typed.go | 4 +- 42 files changed, 255 insertions(+), 143 deletions(-) rename ignite/templates/module/create/files/base/api/{{appName}}/{{moduleName}}/module/{ => {{protoVer}}}/module.pulsar.go.plush (100%) rename ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/module/{ => {{protoVer}}}/module.proto.plush (92%) rename ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/genesis.proto.plush (85%) rename ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/params.proto.plush (100%) rename ignite/templates/module/create/files/base/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/query.proto.plush (92%) rename ignite/templates/module/create/files/ibc/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/packet.proto.plush (100%) rename ignite/templates/module/create/files/msgserver/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/tx.proto.plush (94%) rename ignite/templates/typed/dry/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/{{typeName}}.proto.plush (68%) rename ignite/templates/typed/list/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/{{typeName}}.proto.plush (74%) rename ignite/templates/typed/map/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/{{typeName}}.proto.plush (76%) rename ignite/templates/typed/singleton/files/component/{{protoDir}}/{{appName}}/{{moduleName}}/{ => {{protoVer}}}/{{typeName}}.proto.plush (73%) diff --git a/changelog.md b/changelog.md index 5e8c430bb1..4049c2b245 100644 --- a/changelog.md +++ b/changelog.md @@ -32,6 +32,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..8fbd3a8543 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, @@ -146,13 +147,13 @@ func (s Scaffolder) AddMessage( gens, err = supportMsgServer( gens, s.Tracer(), - s.appPath, &modulecreate.MsgServerOptions{ ModuleName: opts.ModuleName, ModulePath: opts.ModulePath, 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/patch.go b/ignite/services/scaffolder/patch.go index a4da4f813d..27d0b86805 100644 --- a/ignite/services/scaffolder/patch.go +++ b/ignite/services/scaffolder/patch.go @@ -16,11 +16,10 @@ import ( func supportMsgServer( gens []*genny.Generator, replacer placeholder.Replacer, - appPath string, opts *modulecreate.MsgServerOptions, ) ([]*genny.Generator, error) { // Check if convention used - msgServerDefined, err := isMsgServerDefined(appPath, opts.AppName, opts.ProtoDir, opts.ModuleName) + msgServerDefined, err := isMsgServerDefined(opts) if err != nil { return nil, err } @@ -37,8 +36,8 @@ func supportMsgServer( // isMsgServerDefined checks if the module uses the MsgServer convention for transactions // this is checked by verifying the existence of the tx.proto file. -func isMsgServerDefined(appPath, appName, protoPath, moduleName string) (bool, error) { - txProto, err := filepath.Abs(filepath.Join(appPath, protoPath, appName, moduleName, "tx.proto")) +func isMsgServerDefined(opts *modulecreate.MsgServerOptions) (bool, error) { + txProto, err := filepath.Abs(opts.ProtoFile("tx.proto")) if err != nil { return false, err } 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 b649c4607c..e10d34611a 100644 --- a/ignite/services/scaffolder/type.go +++ b/ignite/services/scaffolder/type.go @@ -166,6 +166,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, @@ -181,12 +182,13 @@ func (s Scaffolder) AddType( gens, err = supportMsgServer( gens, s.runner.Tracer(), - s.appPath, &modulecreate.MsgServerOptions{ ModuleName: opts.ModuleName, ModulePath: opts.ModulePath, AppName: opts.AppName, AppPath: opts.AppPath, + ProtoDir: opts.ProtoDir, + ProtoVer: opts.ProtoVer, }, ) if err != nil { diff --git a/ignite/templates/app/options.go b/ignite/templates/app/options.go index 1621505f88..113e241f63 100644 --- a/ignite/templates/app/options.go +++ b/ignite/templates/app/options.go @@ -14,8 +14,3 @@ type Options struct { IsChainMinimal bool IsConsumerChain bool } - -// Validate that options are usable. -func (opts *Options) Validate() error { - return nil -} diff --git a/ignite/templates/ibc/packet.go b/ignite/templates/ibc/packet.go index b2f99b83b7..ffa405df8d 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 @@ -248,8 +256,8 @@ func protoModify(opts *PacketOptions) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range append(opts.Fields.Custom(), opts.AckFields.Custom()...) { - protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) - protoImports = append(protoImports, protoutil.NewImport(protopath)) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) + protoImports = append(protoImports, protoutil.NewImport(protoPath)) } if err := protoutil.AddImports(protoFile, true, protoImports...); err != nil { return errors.Errorf("failed while adding imports to %s: %w", path, 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 @@ -341,7 +349,7 @@ func protoTxModify(opts *PacketOptions) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range opts.Fields.Custom() { - protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protopath)) } if err := protoutil.AddImports(protoFile, true, protoImports...); err != nil { diff --git a/ignite/templates/message/message.go b/ignite/templates/message/message.go index b394e02914..fae97f52a9 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 @@ -155,7 +157,7 @@ func protoTxMessageModify(opts *Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range append(opts.ResFields.Custom(), opts.Fields.Custom()...) { - protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil { diff --git a/ignite/templates/message/options.go b/ignite/templates/message/options.go index b8b00890bd..c1899dd267 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..053c2a7731 100644 --- a/ignite/templates/module/create/base.go +++ b/ignite/templates/module/create/base.go @@ -47,12 +47,14 @@ 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("apiPath", fmt.Sprintf("/%s/%s/%s", appModulePath, opts.ModuleName, opts.ProtoVer)) + ctx.Set("protoPkgName", module.ProtoPackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) + ctx.Set("protoModulePkgName", module.ProtoModulePackageName(appModulePath, opts.ModuleName, opts.ProtoVer)) ctx.Set("toVariableName", strcase.ToLowerCamel) plushhelpers.ExtendPlushContext(ctx) @@ -60,6 +62,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 +91,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 5d24de6aa5..59c95f2a5b 100644 --- a/ignite/templates/module/create/configs.go +++ b/ignite/templates/module/create/configs.go @@ -19,7 +19,8 @@ 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") + // here we do not use opts.ProtoFile as it will append an extra opts.ProtoVer in the path + path := filepath.Join(opts.AppPath, opts.ProtoDir, opts.AppName, opts.ModuleName, "module", opts.ProtoVer, "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 92% 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 index 25ebf95e9a..cebfcb54b6 100644 --- 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 @@ -1,5 +1,5 @@ syntax = "proto3"; -package <%= protoPkgName %>.module; +package <%= protoModulePkgName %>; import "cosmos/app/v1alpha1/module.proto"; 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..e4b0b1588b 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 +} - // Dependencies represents a list of module dependency. - Dependencies []Dependency +// 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) +} - // MsgServerOptions defines options to add MsgServer. - MsgServerOptions struct { - ModuleName string - ModulePath string - AppName string - AppPath string - ProtoDir string - } -) +// Dependency represents a module dependency of a module. +type Dependency struct { + Name string +} + +// Dependencies represents a list of module dependency. +type Dependencies []Dependency // NewDependency returns a new dependency. func NewDependency(name string) Dependency { @@ -89,8 +112,3 @@ func (d Dependencies) Len() int { func (d Dependency) KeeperName() string { return fmt.Sprint(d.Name, "Keeper") } - -// Validate that options are usable. -func (opts *CreateOptions) Validate() error { - return nil -} diff --git a/ignite/templates/module/create/params.go b/ignite/templates/module/create/params.go index 265bf6d487..91fe9ea8ba 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..99674658e8 100644 --- a/ignite/templates/module/module.go +++ b/ignite/templates/module/module.go @@ -8,9 +8,22 @@ import ( ) // ProtoPackageName creates a protocol buffer package name for an app module. -func ProtoPackageName(appModulePath, moduleName string) string { +func ProtoPackageName(appModulePath, moduleName, version string) string { 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 + // "username" might be not be compatible with proto buffer package names. + path[0] = xstrings.NoNumberPrefix(path[0]) + + return cleanProtoPackageName(strings.Join(path, ".")) +} + +// ProtoModulePackageName creates a protocol buffer module package name for an app module. +func ProtoModulePackageName(appModulePath, moduleName, version string) string { + pathArray := strings.Split(appModulePath, "/") + path := []string{pathArray[len(pathArray)-1], moduleName, "module", 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..32065199e0 100644 --- a/ignite/templates/module/module_test.go +++ b/ignite/templates/module/module_test.go @@ -8,58 +8,104 @@ 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, tt.version)) + }) + } +} + +func TestProtoModulePackageName(t *testing.T) { + cases := []struct { + name string + app string + module string + version string + want string + }{ + { + name: "name", + app: "ignite", + module: "test", + version: "v1", + want: "ignite.test.module.v1", + }, + { + name: "name", + app: "ignite", + module: "test", + version: "v2", + want: "ignite.test.module.v2", }, } 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, ProtoModulePackageName(tt.app, tt.module, tt.version)) }) } } diff --git a/ignite/templates/query/options.go b/ignite/templates/query/options.go index 0ee7e1dd21..2e3517c17c 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..35bcd20d96 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 @@ -137,8 +139,8 @@ func protoQueryModify(opts *Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range append(opts.ResFields.Custom(), opts.ReqFields.Custom()...) { - protopath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) - protoImports = append(protoImports, protoutil.NewImport(protopath)) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) + protoImports = append(protoImports, protoutil.NewImport(protoPath)) } if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil { return errors.Errorf("failed to add imports to %s: %w", path, 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..9c7d5645c9 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/list/list.go b/ignite/templates/typed/list/list.go index 7e049cfa99..a176224ca3 100644 --- a/ignite/templates/typed/list/list.go +++ b/ignite/templates/typed/list/list.go @@ -134,7 +134,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range opts.Fields.Custom() { - protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. 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 76% 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 191bf7b201..d8fbeefabc 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 appendFieldsAndMergeCustomImports(Index, 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/map.go b/ignite/templates/typed/map/map.go index cf50de9389..f11175b955 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -224,7 +224,7 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range opts.Fields.Custom() { - protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. @@ -597,7 +597,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range opts.Fields.Custom() { - protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. diff --git a/ignite/templates/typed/options.go b/ignite/templates/typed/options.go index 6163337c46..6daf03d83d 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 @@ -27,17 +28,12 @@ type Options struct { IsIBC bool } -// Validate that options are usable. -func (opts *Options) Validate() error { - return nil -} - // 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..1d04e7f3bc 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/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index 99773b29e9..11601ed959 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -448,7 +448,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { protoImports = append(protoImports, protoutil.NewImport(imp)) } for _, f := range opts.Fields.Custom() { - protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) + protoPath := fmt.Sprintf("%[1]v/%[2]v/%[3]v/%[4]v.proto", opts.AppName, opts.ModuleName, opts.ProtoVer, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. diff --git a/ignite/templates/typed/typed.go b/ignite/templates/typed/typed.go index 5507872cc7..78db94482f 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("Index", opts.Index) 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