From 72e749cbb0bd3601c9318a421c0d4c7b8f0abb27 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Sun, 8 Dec 2024 03:00:37 -0300 Subject: [PATCH] remove genesis placeholders --- ignite/templates/typed/list/list.go | 34 ++++++++++++++----- ignite/templates/typed/map/map.go | 28 +++++++++------ ignite/templates/typed/placeholders.go | 3 +- ignite/templates/typed/singleton/singleton.go | 26 +++++++++----- 4 files changed, 61 insertions(+), 30 deletions(-) diff --git a/ignite/templates/typed/list/list.go b/ignite/templates/typed/list/list.go index cafa8c0194..180ffbc8b6 100644 --- a/ignite/templates/typed/list/list.go +++ b/ignite/templates/typed/list/list.go @@ -326,16 +326,32 @@ func keeperModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunF ) content := replacer.Replace(f.String(), typed.PlaceholderCollectionType, replacementModuleType) - templateKeeperInstantiate := `%[2]vSeq: collections.NewSequence(sb, types.%[2]vCountKey, "%[3]v_seq"), - %[2]v: collections.NewMap(sb, types.%[2]vKey, "%[3]v", collections.Uint64Key, codec.CollValue[types.%[2]v](cdc)), - %[1]v` - replacementInstantiate := fmt.Sprintf( - templateKeeperInstantiate, - typed.PlaceholderCollectionInstantiate, - opts.TypeName.UpperCamel, - opts.TypeName.LowerCamel, + // add parameter to the struct into the new keeper method. + content, err = xast.ModifyFunction( + content, + "NewKeeper", + xast.AppendInsideFuncStruct( + "Keeper", + fmt.Sprintf("%[1]vSeq", opts.TypeName.UpperCamel), + fmt.Sprintf(`collections.NewSequence(sb, types.%[1]vCountKey, "%[2]v_seq")`, + opts.TypeName.UpperCamel, + opts.TypeName.LowerCamel, + ), + -1, + ), + xast.AppendInsideFuncStruct( + "Keeper", + opts.TypeName.UpperCamel, + fmt.Sprintf(`collections.NewMap(sb, types.%[1]vKey, "%[2]v", collections.Uint64Key, codec.CollValue[types.%[1]v](cdc))`, + opts.TypeName.UpperCamel, + opts.TypeName.LowerCamel, + ), + -1, + ), ) - content = replacer.Replace(content, typed.PlaceholderCollectionInstantiate, replacementInstantiate) + if err != nil { + return err + } newFile := genny.NewFileS(path, content) return r.File(newFile) diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index c76563b1c3..2fcf3fa3d1 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -135,16 +135,24 @@ func keeperModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunF ) content := replacer.Replace(f.String(), typed.PlaceholderCollectionType, replacementModuleType) - templateKeeperInstantiate := `%[2]v: collections.NewMap(sb, types.%[2]vKey, "%[3]v", %[4]v, codec.CollValue[types.%[2]v](cdc)), - %[1]v` - replacementInstantiate := fmt.Sprintf( - templateKeeperInstantiate, - typed.PlaceholderCollectionInstantiate, - opts.TypeName.UpperCamel, - opts.TypeName.LowerCamel, - opts.Index.CollectionsKeyValueType(), + // add parameter to the struct into the new keeper method. + content, err = xast.ModifyFunction( + content, + "NewKeeper", + xast.AppendInsideFuncStruct( + "Keeper", + opts.TypeName.UpperCamel, + fmt.Sprintf(`collections.NewMap(sb, types.%[1]vKey, "%[2]v", %[3]v, codec.CollValue[types.%[1]v](cdc))`, + opts.TypeName.UpperCamel, + opts.TypeName.LowerCamel, + opts.Index.CollectionsKeyValueType(), + ), + -1, + ), ) - content = replacer.Replace(content, typed.PlaceholderCollectionInstantiate, replacementInstantiate) + if err != nil { + return err + } newFile := genny.NewFileS(path, content) return r.File(newFile) @@ -468,7 +476,7 @@ func genesisTestsModify(opts *typed.Options) genny.RunFn { // add parameter to the struct into the new method. content, err := xast.ModifyFunction( f.String(), - "TestGenesisState_Validate", + "TestGenesis", xast.AppendInsideFuncStruct( "GenesisState", fmt.Sprintf("%[1]vList", opts.TypeName.UpperCamel), diff --git a/ignite/templates/typed/placeholders.go b/ignite/templates/typed/placeholders.go index 7fc43f9617..9458fbf7f9 100644 --- a/ignite/templates/typed/placeholders.go +++ b/ignite/templates/typed/placeholders.go @@ -14,6 +14,5 @@ const ( PlaceholderAutoCLITx = "// this line is used by ignite scaffolding # autocli/tx" // Placeholders Collections - PlaceholderCollectionType = "// this line is used by starport scaffolding # collection/type" - PlaceholderCollectionInstantiate = "// this line is used by starport scaffolding # collection/instantiate" + PlaceholderCollectionType = "// this line is used by starport scaffolding # collection/type" ) diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index e6431a2ec8..1855069bfe 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -123,15 +123,23 @@ func keeperModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunF ) content := replacer.Replace(f.String(), typed.PlaceholderCollectionType, replacementModuleType) - templateKeeperInstantiate := `%[2]v: collections.NewItem(sb, types.%[2]vKey, "%[3]v", codec.CollValue[types.%[2]v](cdc)), - %[1]v` - replacementInstantiate := fmt.Sprintf( - templateKeeperInstantiate, - typed.PlaceholderCollectionInstantiate, - opts.TypeName.UpperCamel, - opts.TypeName.LowerCamel, + // add parameter to the struct into the new keeper method. + content, err = xast.ModifyFunction( + content, + "NewKeeper", + xast.AppendInsideFuncStruct( + "Keeper", + opts.TypeName.UpperCamel, + fmt.Sprintf(`collections.NewItem(sb, types.%[1]vKey, "%[2]v", codec.CollValue[types.%[1]v](cdc))`, + opts.TypeName.UpperCamel, + opts.TypeName.LowerCamel, + ), + -1, + ), ) - content = replacer.Replace(content, typed.PlaceholderCollectionInstantiate, replacementInstantiate) + if err != nil { + return err + } newFile := genny.NewFileS(path, content) return r.File(newFile) @@ -308,7 +316,7 @@ func genesisTestsModify(opts *typed.Options) genny.RunFn { // add parameter to the struct into the new method. content, err := xast.ModifyFunction( f.String(), - "TestGenesisState_Validate", + "TestGenesis", xast.AppendInsideFuncStruct( "GenesisState", opts.TypeName.UpperCamel,