From 35704fe6cfab346c0da715fb72ea773b0e02feab Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 May 2024 10:48:52 +0200 Subject: [PATCH 1/3] refactor(templates)!: scaffold int64 instead of int32 --- changelog.md | 1 + ignite/cmd/scaffold.go | 4 +-- ignite/pkg/protoanalysis/protoutil/creator.go | 12 ++++----- ignite/templates/field/datatype/int.go | 26 +++++++++---------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/changelog.md b/changelog.md index c8d3e6b8c4..7fcc8c6d6c 100644 --- a/changelog.md +++ b/changelog.md @@ -35,6 +35,7 @@ - [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2` - [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure. - [#4149](https://github.com/ignite/cli/pull/4149) Bump cometbft to `v0.38.7` +- []() Scaffold `int64` instead of `int32` when a field type is `int` ### Fixes diff --git a/ignite/cmd/scaffold.go b/ignite/cmd/scaffold.go index e3902ed888..e1a64e2173 100644 --- a/ignite/cmd/scaffold.go +++ b/ignite/cmd/scaffold.go @@ -35,8 +35,8 @@ Currently supports: | string | - | yes | string | Text type | | array.string | strings | no | []string | List of text type | | bool | - | yes | bool | Boolean type | -| int | - | yes | int32 | Integer type | -| array.int | ints | no | []int32 | List of integers types | +| int | - | yes | int64 | Integer type | +| array.int | ints | no | []int64 | List of integers types | | uint | - | yes | uint64 | Unsigned integer type | | array.uint | uints | no | []uint64 | List of unsigned integers types | | coin | - | no | sdk.Coin | Cosmos SDK coin type | diff --git a/ignite/pkg/protoanalysis/protoutil/creator.go b/ignite/pkg/protoanalysis/protoutil/creator.go index 8f9f5b36d2..534774e452 100644 --- a/ignite/pkg/protoanalysis/protoutil/creator.go +++ b/ignite/pkg/protoanalysis/protoutil/creator.go @@ -320,14 +320,14 @@ func WithFieldOptions(options ...*proto.Option) FieldSpecOptions { // NewField creates a new field statement node: // -// // int32 Foo = 1; -// field := NewField("Foo", "int32", 1) +// // int64 Foo = 1; +// field := NewField("Foo", "int64", 1) // // Fields aren't marked as repeated, required or optional. Use Repeated, Optional // and Required to mark the field as such. // -// // repeated int32 Foo = 1; -// field := NewField("Foo", "int32", 1, Repeated()) +// // repeated int64 Foo = 1; +// field := NewField("Foo", "int64", 1, Repeated()) func NewField(name, typename string, sequence int, opts ...FieldSpecOptions) *proto.NormalField { f := FieldSpec{name: name, typename: typename, sequence: sequence} for _, opt := range opts { @@ -401,10 +401,10 @@ func Extend() MessageSpecOptions { // // // message Foo { // // option (foo) = 1; -// // int32 Bar = 1; +// // int64 Bar = 1; // // } // opt := NewOption("foo", "1") -// field := NewField("int32", "Bar", 1) +// field := NewField("int64", "Bar", 1) // message := NewMessage("Foo", WithMessageOptions(opt), WithFields(field)) // // By default, options are added first, then fields and then enums. diff --git a/ignite/templates/field/datatype/int.go b/ignite/templates/field/datatype/int.go index f1bd859e8d..b1e2544f0b 100644 --- a/ignite/templates/field/datatype/int.go +++ b/ignite/templates/field/datatype/int.go @@ -12,20 +12,20 @@ import ( var ( // DataInt is an int data type definition. DataInt = DataType{ - DataType: func(string) string { return "int32" }, - CollectionsKeyValueName: func(string) string { return "collections.Int32Key" }, + DataType: func(string) string { return "int64" }, + CollectionsKeyValueName: func(string) string { return "collections.Int64Key" }, DefaultTestValue: "111", - ValueLoop: "int32(i)", + ValueLoop: "int64(i)", ValueIndex: "0", ValueInvalidIndex: "100000", ProtoType: func(_, name string, index int) string { - return fmt.Sprintf("int32 %s = %d", name, index) + return fmt.Sprintf("int64 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: %d,\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { - return fmt.Sprintf(`%s%s, err := cast.ToInt32E(args[%d]) + return fmt.Sprintf(`%s%s, err := cast.ToInt64E(args[%d]) if err != nil { return err }`, @@ -33,33 +33,33 @@ var ( }, ToBytes: func(name string) string { return fmt.Sprintf(`%[1]vBytes := make([]byte, 4) - binary.BigEndian.PutUint32(%[1]vBytes, uint32(%[1]v))`, name) + binary.BigEndian.PutUint64(%[1]vBytes, uint64(%[1]v))`, name) }, ToString: func(name string) string { return fmt.Sprintf("strconv.Itoa(int(%s))", name) }, ToProtoField: func(_, name string, index int) *proto.NormalField { - return protoutil.NewField(name, "int32", index) + return protoutil.NewField(name, "int64", index) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}}, } // DataIntSlice is an int array data type definition. DataIntSlice = DataType{ - DataType: func(string) string { return "[]int32" }, + DataType: func(string) string { return "[]int64" }, CollectionsKeyValueName: func(string) string { return collectionValueComment }, DefaultTestValue: "1,2,3,4,5", ProtoType: func(_, name string, index int) string { - return fmt.Sprintf("repeated int32 %s = %d", name, index) + return fmt.Sprintf("repeated int64 %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { - return fmt.Sprintf("%s: []int32{%d},\n", name.UpperCamel, value) + return fmt.Sprintf("%s: []int64{%d},\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf(`%[1]vCast%[2]v := strings.Split(args[%[3]v], listSeparator) - %[1]v%[2]v := make([]int32, len(%[1]vCast%[2]v)) + %[1]v%[2]v := make([]int64, len(%[1]vCast%[2]v)) for i, arg := range %[1]vCast%[2]v { - value, err := cast.ToInt32E(arg) + value, err := cast.ToInt64E(arg) if err != nil { return err } @@ -67,7 +67,7 @@ var ( }`, prefix, name.UpperCamel, argIndex) }, ToProtoField: func(_, name string, index int) *proto.NormalField { - return protoutil.NewField(name, "int32", index, protoutil.Repeated()) + return protoutil.NewField(name, "int64", index, protoutil.Repeated()) }, GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}, {Name: "strings"}}, NonIndex: true, From 3dde9c445ec491e860a69e660db9f27e1055680b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 23 May 2024 10:50:09 +0200 Subject: [PATCH 2/3] changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 7fcc8c6d6c..25bf15ac07 100644 --- a/changelog.md +++ b/changelog.md @@ -35,7 +35,7 @@ - [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2` - [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure. - [#4149](https://github.com/ignite/cli/pull/4149) Bump cometbft to `v0.38.7` -- []() Scaffold `int64` instead of `int32` when a field type is `int` +- [#4167](https://github.com/ignite/cli/pull/4167) Scaffold `int64` instead of `int32` when a field type is `int` ### Fixes From eb41aa9c60b0908bb40a56b938536de93991162f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 28 May 2024 13:00:15 +0200 Subject: [PATCH 3/3] fix map --- ignite/templates/field/datatype/int.go | 2 +- ignite/templates/typed/map/map.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ignite/templates/field/datatype/int.go b/ignite/templates/field/datatype/int.go index b1e2544f0b..17d3f0ad92 100644 --- a/ignite/templates/field/datatype/int.go +++ b/ignite/templates/field/datatype/int.go @@ -36,7 +36,7 @@ var ( binary.BigEndian.PutUint64(%[1]vBytes, uint64(%[1]v))`, name) }, ToString: func(name string) string { - return fmt.Sprintf("strconv.Itoa(int(%s))", name) + return fmt.Sprintf("strconv.FormatInt(%s, 10)", name) }, ToProtoField: func(_, name string, index int) *proto.NormalField { return protoutil.NewField(name, "int64", index) diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index 9b746a95cb..c6219f33f4 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -365,7 +365,7 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn content = replacer.Replace(content, typed.PlaceholderGenesisTypesDefault, replacementTypesDefault) // lines of code to call the key function with the indexes of the element - keyCall := fmt.Sprintf("string(elem.%s)", opts.Index.Name.UpperCamel) + keyCall := fmt.Sprintf(`fmt.Sprint(elem.%s)`, opts.Index.Name.UpperCamel) templateTypesValidate := `// Check for duplicated index in %[2]v %[2]vIndexMap := make(map[string]struct{})