Skip to content

Commit 1ee2658

Browse files
authored
refactor(templates)!: scaffold int64 instead of int32 (#4167)
* refactor(templates)!: scaffold int64 instead of int32 * changelog * fix map
1 parent de025f3 commit 1ee2658

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2`
3636
- [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure.
3737
- [#4149](https://github.com/ignite/cli/pull/4149) Bump cometbft to `v0.38.7`
38+
- [#4167](https://github.com/ignite/cli/pull/4167) Scaffold `int64` instead of `int32` when a field type is `int`
3839
- [#4168](https://github.com/ignite/cli/pull/4168) Bump IBC to `v8.3.1`
3940

4041
### Fixes

ignite/cmd/scaffold.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Currently supports:
3535
| string | - | yes | string | Text type |
3636
| array.string | strings | no | []string | List of text type |
3737
| bool | - | yes | bool | Boolean type |
38-
| int | - | yes | int32 | Integer type |
39-
| array.int | ints | no | []int32 | List of integers types |
38+
| int | - | yes | int64 | Integer type |
39+
| array.int | ints | no | []int64 | List of integers types |
4040
| uint | - | yes | uint64 | Unsigned integer type |
4141
| array.uint | uints | no | []uint64 | List of unsigned integers types |
4242
| coin | - | no | sdk.Coin | Cosmos SDK coin type |

ignite/pkg/protoanalysis/protoutil/creator.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,14 @@ func WithFieldOptions(options ...*proto.Option) FieldSpecOptions {
320320

321321
// NewField creates a new field statement node:
322322
//
323-
// // int32 Foo = 1;
324-
// field := NewField("Foo", "int32", 1)
323+
// // int64 Foo = 1;
324+
// field := NewField("Foo", "int64", 1)
325325
//
326326
// Fields aren't marked as repeated, required or optional. Use Repeated, Optional
327327
// and Required to mark the field as such.
328328
//
329-
// // repeated int32 Foo = 1;
330-
// field := NewField("Foo", "int32", 1, Repeated())
329+
// // repeated int64 Foo = 1;
330+
// field := NewField("Foo", "int64", 1, Repeated())
331331
func NewField(name, typename string, sequence int, opts ...FieldSpecOptions) *proto.NormalField {
332332
f := FieldSpec{name: name, typename: typename, sequence: sequence}
333333
for _, opt := range opts {
@@ -401,10 +401,10 @@ func Extend() MessageSpecOptions {
401401
//
402402
// // message Foo {
403403
// // option (foo) = 1;
404-
// // int32 Bar = 1;
404+
// // int64 Bar = 1;
405405
// // }
406406
// opt := NewOption("foo", "1")
407-
// field := NewField("int32", "Bar", 1)
407+
// field := NewField("int64", "Bar", 1)
408408
// message := NewMessage("Foo", WithMessageOptions(opt), WithFields(field))
409409
//
410410
// By default, options are added first, then fields and then enums.

ignite/templates/field/datatype/int.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,62 @@ import (
1212
var (
1313
// DataInt is an int data type definition.
1414
DataInt = DataType{
15-
DataType: func(string) string { return "int32" },
16-
CollectionsKeyValueName: func(string) string { return "collections.Int32Key" },
15+
DataType: func(string) string { return "int64" },
16+
CollectionsKeyValueName: func(string) string { return "collections.Int64Key" },
1717
DefaultTestValue: "111",
18-
ValueLoop: "int32(i)",
18+
ValueLoop: "int64(i)",
1919
ValueIndex: "0",
2020
ValueInvalidIndex: "100000",
2121
ProtoType: func(_, name string, index int) string {
22-
return fmt.Sprintf("int32 %s = %d", name, index)
22+
return fmt.Sprintf("int64 %s = %d", name, index)
2323
},
2424
GenesisArgs: func(name multiformatname.Name, value int) string {
2525
return fmt.Sprintf("%s: %d,\n", name.UpperCamel, value)
2626
},
2727
CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string {
28-
return fmt.Sprintf(`%s%s, err := cast.ToInt32E(args[%d])
28+
return fmt.Sprintf(`%s%s, err := cast.ToInt64E(args[%d])
2929
if err != nil {
3030
return err
3131
}`,
3232
prefix, name.UpperCamel, argIndex)
3333
},
3434
ToBytes: func(name string) string {
3535
return fmt.Sprintf(`%[1]vBytes := make([]byte, 4)
36-
binary.BigEndian.PutUint32(%[1]vBytes, uint32(%[1]v))`, name)
36+
binary.BigEndian.PutUint64(%[1]vBytes, uint64(%[1]v))`, name)
3737
},
3838
ToString: func(name string) string {
39-
return fmt.Sprintf("strconv.Itoa(int(%s))", name)
39+
return fmt.Sprintf("strconv.FormatInt(%s, 10)", name)
4040
},
4141
ToProtoField: func(_, name string, index int) *proto.NormalField {
42-
return protoutil.NewField(name, "int32", index)
42+
return protoutil.NewField(name, "int64", index)
4343
},
4444
GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}},
4545
}
4646

4747
// DataIntSlice is an int array data type definition.
4848
DataIntSlice = DataType{
49-
DataType: func(string) string { return "[]int32" },
49+
DataType: func(string) string { return "[]int64" },
5050
CollectionsKeyValueName: func(string) string { return collectionValueComment },
5151
DefaultTestValue: "1,2,3,4,5",
5252
ProtoType: func(_, name string, index int) string {
53-
return fmt.Sprintf("repeated int32 %s = %d", name, index)
53+
return fmt.Sprintf("repeated int64 %s = %d", name, index)
5454
},
5555
GenesisArgs: func(name multiformatname.Name, value int) string {
56-
return fmt.Sprintf("%s: []int32{%d},\n", name.UpperCamel, value)
56+
return fmt.Sprintf("%s: []int64{%d},\n", name.UpperCamel, value)
5757
},
5858
CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string {
5959
return fmt.Sprintf(`%[1]vCast%[2]v := strings.Split(args[%[3]v], listSeparator)
60-
%[1]v%[2]v := make([]int32, len(%[1]vCast%[2]v))
60+
%[1]v%[2]v := make([]int64, len(%[1]vCast%[2]v))
6161
for i, arg := range %[1]vCast%[2]v {
62-
value, err := cast.ToInt32E(arg)
62+
value, err := cast.ToInt64E(arg)
6363
if err != nil {
6464
return err
6565
}
6666
%[1]v%[2]v[i] = value
6767
}`, prefix, name.UpperCamel, argIndex)
6868
},
6969
ToProtoField: func(_, name string, index int) *proto.NormalField {
70-
return protoutil.NewField(name, "int32", index, protoutil.Repeated())
70+
return protoutil.NewField(name, "int64", index, protoutil.Repeated())
7171
},
7272
GoCLIImports: []GoImport{{Name: "github.com/spf13/cast"}, {Name: "strings"}},
7373
NonIndex: true,

ignite/templates/typed/map/map.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func genesisTypesModify(replacer placeholder.Replacer, opts *typed.Options) genn
365365
content = replacer.Replace(content, typed.PlaceholderGenesisTypesDefault, replacementTypesDefault)
366366

367367
// lines of code to call the key function with the indexes of the element
368-
keyCall := fmt.Sprintf("string(elem.%s)", opts.Index.Name.UpperCamel)
368+
keyCall := fmt.Sprintf(`fmt.Sprint(elem.%s)`, opts.Index.Name.UpperCamel)
369369

370370
templateTypesValidate := `// Check for duplicated index in %[2]v
371371
%[2]vIndexMap := make(map[string]struct{})

0 commit comments

Comments
 (0)