diff --git a/changelog.md b/changelog.md index ce58b2a314..4097db2a40 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` +- [#4167](https://github.com/ignite/cli/pull/4167) Scaffold `int64` instead of `int32` when a field type is `int` - [#4168](https://github.com/ignite/cli/pull/4168) Bump IBC to `v8.3.1` ### 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..17d3f0ad92 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) + return fmt.Sprintf("strconv.FormatInt(%s, 10)", 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, 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{})