diff --git a/ignite/services/scaffolder/component.go b/ignite/services/scaffolder/component.go index e7c22232ad..c5b478f339 100644 --- a/ignite/services/scaffolder/component.go +++ b/ignite/services/scaffolder/component.go @@ -117,9 +117,15 @@ func checkCustomTypes(ctx context.Context, appPath, appName, protoDir, module st } if _, ok := datatype.IsSupportedType(datatype.Name(ft)); !ok { + // sanitize the custom type name + if str := strings.Split(ft, "."); len(str) > 1 { // <- sanitize in IsSupportedType + ft = str[1] + } + customFieldTypes = append(customFieldTypes, ft) } } + return protoanalysis.HasMessages(ctx, path, customFieldTypes...) } diff --git a/ignite/templates/field/datatype/custom.go b/ignite/templates/field/datatype/custom.go index 614967e7ed..6d8e4631a1 100644 --- a/ignite/templates/field/datatype/custom.go +++ b/ignite/templates/field/datatype/custom.go @@ -33,3 +33,27 @@ var DataCustom = DataType{ GoCLIImports: []GoImport{{Name: "encoding/json"}}, NonIndex: true, } + +// DataCustomSlice is a custom data array type definition. +var DataCustomSlice = DataType{ + DataType: func(datatype string) string { return fmt.Sprintf("[]*%s", datatype) }, + DefaultTestValue: "null", + ProtoType: func(datatype, name string, index int) string { + return fmt.Sprintf("repeated %s %s = %d", datatype, name, index) + }, + GenesisArgs: func(name multiformatname.Name, value int) string { + return fmt.Sprintf("%s: []types.%s{},\n", name.UpperCamel, name.UpperCamel) + }, + CLIArgs: func(name multiformatname.Name, datatype, prefix string, argIndex int) string { + return fmt.Sprintf(`%[1]v%[2]v := []types.%[3]v{} + err = json.Unmarshal([]byte(args[%[4]v]), %[1]v%[2]v) + if err != nil { + return err + }`, prefix, name.UpperCamel, datatype, argIndex) + }, + ToProtoField: func(datatype, name string, index int) *proto.NormalField { + return protoutil.NewField(name, datatype, index, protoutil.Repeated()) + }, + GoCLIImports: []GoImport{{Name: "encoding/json"}}, + NonIndex: true, +} diff --git a/ignite/templates/field/datatype/types.go b/ignite/templates/field/datatype/types.go index c817cea413..e3d3d9c787 100644 --- a/ignite/templates/field/datatype/types.go +++ b/ignite/templates/field/datatype/types.go @@ -32,6 +32,8 @@ const ( Bytes Name = "bytes" // Custom represents the custom type name. Custom Name = Name(TypeCustom) + // CustomSlice represents the custom array type name. + CustomSlice Name = "array." + TypeCustom // StringSliceAlias represents the string array type name alias. StringSliceAlias Name = "strings" @@ -42,8 +44,8 @@ const ( // CoinSliceAlias represents the coin array type name alias. CoinSliceAlias Name = "coins" - // TypeCustom represents the string type name id. - TypeCustom = "customstarporttype" + // TypeCustom represents the custom type name. + TypeCustom = "customignitetype" collectionValueComment = "/* Add collection key value */" ) @@ -65,6 +67,7 @@ var supportedTypes = map[Name]DataType{ Coins: DataCoinSlice, CoinSliceAlias: DataCoinSlice, Custom: DataCustom, + CustomSlice: DataCustomSlice, } // Name represents the Alias Name for the data type.