Skip to content

Commit

Permalink
remove genesis placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Dec 8, 2024
1 parent bf48141 commit 72e749c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
34 changes: 25 additions & 9 deletions ignite/templates/typed/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 18 additions & 10 deletions ignite/templates/typed/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions ignite/templates/typed/placeholders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
26 changes: 17 additions & 9 deletions ignite/templates/typed/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 72e749c

Please sign in to comment.