From 45088739f8d64f604a23a2da75a68c7dca318922 Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 20 Jun 2024 13:44:35 +0300 Subject: [PATCH] fix ignite --- ignite/cmd/chain.go | 6 +-- ignite/cmd/scaffold.go | 45 +++++++++---------- ignite/config/chain/base/config.go | 2 +- ignite/pkg/xgenny/xgenny.go | 11 +++++ ignite/services/chain/chain.go | 2 +- ignite/services/scaffolder/component.go | 2 +- ignite/services/scaffolder/patch.go | 2 +- ignite/services/scaffolder/scaffolder.go | 7 +-- ignite/templates/ibc/oracle.go | 4 +- ignite/templates/ibc/packet.go | 8 ++-- ignite/templates/message/message.go | 6 +-- ignite/templates/module/create/ibc.go | 2 +- ignite/templates/query/query.go | 4 +- ignite/templates/typed/list/list.go | 2 +- ignite/templates/typed/map/map.go | 4 +- ignite/templates/typed/options.go | 4 +- ignite/templates/typed/singleton/singleton.go | 2 +- 17 files changed, 60 insertions(+), 53 deletions(-) diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 5a884c7a26..1bb0fc5093 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -200,9 +200,9 @@ func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (e } // Confirm before migrating the config if there are uncommitted changes - if err := confirmWhenUncommittedChanges(session, appPath); err != nil { - return err - } + // if err := confirmWhenUncommittedChanges(session, appPath); err != nil { + // return err + // } } else { session.Printf("%s %s\n", icons.Info, colors.Infof(msgMigration, version, chainconfig.LatestVersion)) } diff --git a/ignite/cmd/scaffold.go b/ignite/cmd/scaffold.go index fbc3fa09bd..e76bc6b704 100644 --- a/ignite/cmd/scaffold.go +++ b/ignite/cmd/scaffold.go @@ -1,15 +1,11 @@ package ignitecmd import ( - "errors" - - "github.com/manifoldco/promptui" "github.com/spf13/cobra" flag "github.com/spf13/pflag" "github.com/ignite/cli/ignite/pkg/cliui" "github.com/ignite/cli/ignite/pkg/placeholder" - "github.com/ignite/cli/ignite/pkg/xgit" "github.com/ignite/cli/ignite/services/scaffolder" ) @@ -176,34 +172,33 @@ func gitChangesConfirmPreRunHandler(cmd *cobra.Command, _ []string) error { return nil } - appPath := flagGetPath(cmd) session := cliui.New() defer session.End() - return confirmWhenUncommittedChanges(session, appPath) -} - -func confirmWhenUncommittedChanges(session *cliui.Session, appPath string) error { - cleanState, err := xgit.AreChangesCommitted(appPath) - if err != nil { - return err - } - - if !cleanState { - session.Println(msgCommitPrefix) - if err := session.AskConfirm(msgCommitPrompt); err != nil { - if errors.Is(err, promptui.ErrAbort) { - return errors.New("No") - } - - return err - } - } - return nil } +// func confirmWhenUncommittedChanges(session *cliui.Session, appPath string) error { +// cleanState, err := xgit.AreChangesCommitted(appPath) +// if err != nil { +// return err +// } + +// if !cleanState { +// session.Println(msgCommitPrefix) +// if err := session.AskConfirm(msgCommitPrompt); err != nil { +// if errors.Is(err, promptui.ErrAbort) { +// return errors.New("No") +// } + +// return err +// } +// } + +// return nil +// } + func flagSetScaffoldType() *flag.FlagSet { f := flag.NewFlagSet("", flag.ContinueOnError) f.String(flagModule, "", "specify which module to generate code in") diff --git a/ignite/config/chain/base/config.go b/ignite/config/chain/base/config.go index b71de4e1ef..25397eafd4 100644 --- a/ignite/config/chain/base/config.go +++ b/ignite/config/chain/base/config.go @@ -179,7 +179,7 @@ func DefaultConfig() Config { return Config{ Build: Build{ Proto: Proto{ - Path: "proto", + Path: "proto/lavanet", ThirdPartyPaths: []string{"third_party/proto", "proto_vendor"}, }, }, diff --git a/ignite/pkg/xgenny/xgenny.go b/ignite/pkg/xgenny/xgenny.go index 4338a58c7f..b2fe34cd76 100644 --- a/ignite/pkg/xgenny/xgenny.go +++ b/ignite/pkg/xgenny/xgenny.go @@ -70,6 +70,17 @@ func Transformer(ctx *plush.Context) genny.Transformer { if err != nil { return f, errors.Wrap(err, f.Name()) } + var fileName string + var content string + if !strings.Contains(f.Name(), "proto/lavanet") && strings.Contains(f.Name(), ".proto") { + orig := f.Name() + _ = orig + fileName = strings.Replace(f.Name(), "proto/", "proto/lavanet/", -1) + content = strings.Replace(s, "lava.", "lavanet.lava.", -1) + } + if fileName != "" { + return genny.NewFileS(fileName, content), nil + } return genny.NewFileS(f.Name(), s), nil }) t.StripExt = true diff --git a/ignite/services/chain/chain.go b/ignite/services/chain/chain.go index 2bc222ab57..52cd96e145 100644 --- a/ignite/services/chain/chain.go +++ b/ignite/services/chain/chain.go @@ -27,7 +27,7 @@ var appBackendSourceWatchPaths = []string{ "app", "cmd", "x", - "proto", + "proto/lavanet", "third_party", } diff --git a/ignite/services/scaffolder/component.go b/ignite/services/scaffolder/component.go index 9c12bddd0c..623f91e229 100644 --- a/ignite/services/scaffolder/component.go +++ b/ignite/services/scaffolder/component.go @@ -22,7 +22,7 @@ const ( componentQuery = "query" componentPacket = "packet" - protoFolder = "proto" + protoFolder = "proto/lavanet" ) // checkComponentValidity performs various checks common to all components to verify if it can be scaffolded. diff --git a/ignite/services/scaffolder/patch.go b/ignite/services/scaffolder/patch.go index c8159145d9..015ee17924 100644 --- a/ignite/services/scaffolder/patch.go +++ b/ignite/services/scaffolder/patch.go @@ -82,7 +82,7 @@ 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, moduleName string) (bool, error) { - txProto, err := filepath.Abs(filepath.Join(appPath, "proto", appName, moduleName, "tx.proto")) + txProto, err := filepath.Abs(filepath.Join(appPath, "proto/lavanet", appName, moduleName, "tx.proto")) if err != nil { return false, err } diff --git a/ignite/services/scaffolder/scaffolder.go b/ignite/services/scaffolder/scaffolder.go index 78eb6520d4..40409e22bd 100644 --- a/ignite/services/scaffolder/scaffolder.go +++ b/ignite/services/scaffolder/scaffolder.go @@ -74,9 +74,9 @@ func finish(ctx context.Context, cacheStorage cache.Storage, path, gomodPath str } func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodPath string) error { - if err := cosmosgen.InstallDepTools(ctx, projectPath); err != nil { - return err - } + // if err := cosmosgen.InstallDepTools(ctx, projectPath); err != nil { + // return err + // } confpath, err := chainconfig.LocateDefault(projectPath) if err != nil { @@ -87,6 +87,7 @@ func protoc(ctx context.Context, cacheStorage cache.Storage, projectPath, gomodP return err } + conf.Build.Proto.Path = "proto/lavanet" options := []cosmosgen.Option{ cosmosgen.WithGoGeneration(gomodPath), cosmosgen.IncludeDirs(conf.Build.Proto.ThirdPartyPaths), diff --git a/ignite/templates/ibc/oracle.go b/ignite/templates/ibc/oracle.go index c78ba8442a..a4b68f7d3f 100644 --- a/ignite/templates/ibc/oracle.go +++ b/ignite/templates/ibc/oracle.go @@ -117,7 +117,7 @@ func moduleOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genn // Deprecated: This function is no longer maintained. func protoQueryOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "query.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "query.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -172,7 +172,7 @@ message QueryLast%[2]vIdResponse {int64 request_id = 1;} // Deprecated: This function is no longer maintained. func protoTxOracleModify(replacer placeholder.Replacer, opts *OracleOptions) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/ibc/packet.go b/ignite/templates/ibc/packet.go index 0ace5493e3..becf07ca1f 100644 --- a/ignite/templates/ibc/packet.go +++ b/ignite/templates/ibc/packet.go @@ -180,7 +180,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, "proto", opts.AppName, opts.ModuleName, "packet.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "packet.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -245,7 +245,7 @@ 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) + protopath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protopath)) } if err := protoutil.AddImports(protoFile, true, protoImports...); err != nil { @@ -287,7 +287,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, "proto", opts.AppName, opts.ModuleName, "tx.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -329,7 +329,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, 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 256c41443c..a30894c8a3 100644 --- a/ignite/templates/message/message.go +++ b/ignite/templates/message/message.go @@ -87,7 +87,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, "proto", opts.AppName, opts.ModuleName, "tx.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -111,7 +111,7 @@ func protoTxRPCModify(opts *Options) genny.RunFn { func protoTxMessageModify(opts *Options) genny.RunFn { return func(r *genny.Runner) error { - path := filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, "tx.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "tx.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -141,7 +141,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil { diff --git a/ignite/templates/module/create/ibc.go b/ignite/templates/module/create/ibc.go index 92331b6059..566872e1eb 100644 --- a/ignite/templates/module/create/ibc.go +++ b/ignite/templates/module/create/ibc.go @@ -125,7 +125,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, "proto", opts.AppName, opts.ModuleName, "genesis.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "genesis.proto") f, err := r.Disk.Find(path) if err != nil { return err diff --git a/ignite/templates/query/query.go b/ignite/templates/query/query.go index 1072d5beca..99fb84b6de 100644 --- a/ignite/templates/query/query.go +++ b/ignite/templates/query/query.go @@ -66,7 +66,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, "proto", opts.AppName, opts.ModuleName, "query.proto") + path := filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, "query.proto") f, err := r.Disk.Find(path) if err != nil { return err @@ -132,7 +132,7 @@ 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) + protopath := fmt.Sprintf("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protopath)) } if err = protoutil.AddImports(protoFile, true, protoImports...); err != nil { diff --git a/ignite/templates/typed/list/list.go b/ignite/templates/typed/list/list.go index 5c86a227a4..ee15ed57ae 100644 --- a/ignite/templates/typed/list/list.go +++ b/ignite/templates/typed/list/list.go @@ -121,7 +121,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index a88cc786ae..03bbcd5e3a 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -186,7 +186,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback. @@ -539,7 +539,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, 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 25f1002577..7d3d60af0c 100644 --- a/ignite/templates/typed/options.go +++ b/ignite/templates/typed/options.go @@ -33,10 +33,10 @@ func (opts *Options) Validate() error { // ProtoPath returns the path to the proto folder within the generated app. func (opts *Options) ProtoPath(fname string) string { - return filepath.Join(opts.AppPath, "proto", opts.AppName, opts.ModuleName, fname) + return filepath.Join(opts.AppPath, "proto/lavanet", opts.AppName, opts.ModuleName, 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("lavanet/%s/%s/%s.proto", opts.AppName, opts.ModuleName, opts.TypeName.Snake)) } diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index 98966e9084..b3d156a48d 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -384,7 +384,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("lavanet/%[1]v/%[2]v/%[3]v.proto", opts.AppName, opts.ModuleName, f) protoImports = append(protoImports, protoutil.NewImport(protoPath)) } // we already know an import exists, pass false for fallback.