From c1f14e8a16c76823a802f75dccac1b80c46142eb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 18 May 2025 02:02:40 +0200 Subject: [PATCH 1/5] feat: add address type --- ignite/templates/field/datatype/address.go | 42 +++++++++++++++++++ ignite/templates/field/datatype/types.go | 3 ++ ignite/templates/field/datatype/types_test.go | 5 +++ 3 files changed, 50 insertions(+) create mode 100644 ignite/templates/field/datatype/address.go diff --git a/ignite/templates/field/datatype/address.go b/ignite/templates/field/datatype/address.go new file mode 100644 index 0000000000..b7df6b91fd --- /dev/null +++ b/ignite/templates/field/datatype/address.go @@ -0,0 +1,42 @@ +package datatype + +import ( + "fmt" + + "github.com/emicklei/proto" + + "github.com/ignite/cli/v29/ignite/pkg/multiformatname" + "github.com/ignite/cli/v29/ignite/pkg/protoanalysis/protoutil" +) + +// DataAddress address (string) data type definition. +var DataAddress = DataType{ + DataType: func(string) string { return "string" }, + CollectionsKeyValueName: func(string) string { return "collections.StringKey" }, + DefaultTestValue: "cosmos1abcdefghijklmnopqrstuvwxyz0123456", + ValueLoop: "fmt.Sprintf(\"cosmos1abcdef%d\", i)", + ValueIndex: "\"cosmos1abcdefghijklmnopqrstuvwxyz0123456\"", + ValueInvalidIndex: "\"cosmos1invalid\"", + ProtoType: func(_, name string, index int) string { + return fmt.Sprintf("string %s = %d [(cosmos_proto.scalar) = \"cosmos.AddressString\"]", name, index) + }, + GenesisArgs: func(name multiformatname.Name, value int) string { + return fmt.Sprintf("%s: \"cosmos1address%d\",\n", name.UpperCamel, value) + }, + CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { + return fmt.Sprintf("%s%s := args[%d]", prefix, name.UpperCamel, argIndex) + }, + ToBytes: func(name string) string { + return fmt.Sprintf("%[1]vBytes := []byte(%[1]v)", name) + }, + ToString: func(name string) string { + return name + }, + ToProtoField: func(_, name string, index int) *proto.NormalField { + field := protoutil.NewField(name, "string", index) + option := protoutil.NewOption("cosmos_proto.scalar", "\"cosmos.AddressString\"", protoutil.Custom()) + field.Options = append(field.Options, option) + return field + }, + ProtoImports: []string{"cosmos_proto/cosmos.proto"}, +} diff --git a/ignite/templates/field/datatype/types.go b/ignite/templates/field/datatype/types.go index f886878e5d..87b0a66d0b 100644 --- a/ignite/templates/field/datatype/types.go +++ b/ignite/templates/field/datatype/types.go @@ -34,6 +34,8 @@ const ( Coins Name = "array.coin" // Bytes represents the bytes type name. Bytes Name = "bytes" + // Address represents the address type name. + Address Name = "address" // Custom represents the custom type name. Custom Name = Name(TypeCustom) @@ -70,6 +72,7 @@ var supportedTypes = map[Name]DataType{ Coin: DataCoin, Coins: DataCoinSlice, CoinSliceAlias: DataCoinSlice, + Address: DataAddress, Custom: DataCustom, } diff --git a/ignite/templates/field/datatype/types_test.go b/ignite/templates/field/datatype/types_test.go index 5cf3530816..d011a1c485 100644 --- a/ignite/templates/field/datatype/types_test.go +++ b/ignite/templates/field/datatype/types_test.go @@ -89,6 +89,11 @@ func TestIsSupportedType(t *testing.T) { typename: datatype.CoinSliceAlias, ok: true, }, + { + name: "address", + typename: datatype.Address, + ok: true, + }, { name: "invalid type name", typename: datatype.Name("invalid"), From 45c0061c3ea7840d30fb2d5cb8d5a05d8972d17d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 18 May 2025 02:08:48 +0200 Subject: [PATCH 2/5] updates --- changelog.md | 4 ++++ ignite/templates/field/datatype/address.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 5b1221475b..a0f0862b4d 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- [#4687](https://github.com/ignite/cli/pull/4687) Add address type with `scalar` annotations. + ## [`v29.0.0-rc.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-rc.1) ### Features diff --git a/ignite/templates/field/datatype/address.go b/ignite/templates/field/datatype/address.go index b7df6b91fd..4e17f21729 100644 --- a/ignite/templates/field/datatype/address.go +++ b/ignite/templates/field/datatype/address.go @@ -18,7 +18,7 @@ var DataAddress = DataType{ ValueIndex: "\"cosmos1abcdefghijklmnopqrstuvwxyz0123456\"", ValueInvalidIndex: "\"cosmos1invalid\"", ProtoType: func(_, name string, index int) string { - return fmt.Sprintf("string %s = %d [(cosmos_proto.scalar) = \"cosmos.AddressString\"]", name, index) + return fmt.Sprintf(`string %s = %d [(cosmos_proto.scalar) = "cosmos.AddressString"]`, name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: \"cosmos1address%d\",\n", name.UpperCamel, value) @@ -34,7 +34,7 @@ var DataAddress = DataType{ }, ToProtoField: func(_, name string, index int) *proto.NormalField { field := protoutil.NewField(name, "string", index) - option := protoutil.NewOption("cosmos_proto.scalar", "\"cosmos.AddressString\"", protoutil.Custom()) + option := protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom()) field.Options = append(field.Options, option) return field }, From ad2ed044819841a43bd82b8a54eba1c73b8a014d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 20 May 2025 16:18:27 +0200 Subject: [PATCH 3/5] fix + integration test --- ignite/templates/field/datatype/address.go | 2 +- integration/other_components/cmd_message_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ignite/templates/field/datatype/address.go b/ignite/templates/field/datatype/address.go index 4e17f21729..17dd8410db 100644 --- a/ignite/templates/field/datatype/address.go +++ b/ignite/templates/field/datatype/address.go @@ -18,7 +18,7 @@ var DataAddress = DataType{ ValueIndex: "\"cosmos1abcdefghijklmnopqrstuvwxyz0123456\"", ValueInvalidIndex: "\"cosmos1invalid\"", ProtoType: func(_, name string, index int) string { - return fmt.Sprintf(`string %s = %d [(cosmos_proto.scalar) = "cosmos.AddressString"]`, name, index) + return fmt.Sprintf("string %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { return fmt.Sprintf("%s: \"cosmos1address%d\",\n", name.UpperCamel, value) diff --git a/integration/other_components/cmd_message_test.go b/integration/other_components/cmd_message_test.go index 98327acfb3..6e2be81825 100644 --- a/integration/other_components/cmd_message_test.go +++ b/integration/other_components/cmd_message_test.go @@ -26,6 +26,7 @@ func TestGenerateAnAppWithMessage(t *testing.T) { "text", "vote:int", "like:bool", + "from:address", "-r", "foo,bar:int,foobar:bool", ), From 6847117dcf8fb65a4d3594b0ee717f5157991d62 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 20 May 2025 16:37:24 +0200 Subject: [PATCH 4/5] add to signer field --- changelog.md | 2 +- ignite/templates/field/datatype/address.go | 2 +- ignite/templates/ibc/packet.go | 7 ++++++- ignite/templates/message/message.go | 1 + ignite/templates/typed/list/list.go | 1 + ignite/templates/typed/map/map.go | 1 + ignite/templates/typed/singleton/singleton.go | 1 + 7 files changed, 12 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index a0f0862b4d..70471113f2 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,7 @@ ### Features -- [#4687](https://github.com/ignite/cli/pull/4687) Add address type with `scalar` annotations. +- [#4687](https://github.com/ignite/cli/pull/4687) Add address type with `scalar` annotations, and add `scalar` type to signer field. ## [`v29.0.0-rc.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-rc.1) diff --git a/ignite/templates/field/datatype/address.go b/ignite/templates/field/datatype/address.go index 17dd8410db..0b6817df50 100644 --- a/ignite/templates/field/datatype/address.go +++ b/ignite/templates/field/datatype/address.go @@ -21,7 +21,7 @@ var DataAddress = DataType{ return fmt.Sprintf("string %s = %d", name, index) }, GenesisArgs: func(name multiformatname.Name, value int) string { - return fmt.Sprintf("%s: \"cosmos1address%d\",\n", name.UpperCamel, value) + return fmt.Sprintf("%s: \"%d\",\n", name.UpperCamel, value) }, CLIArgs: func(name multiformatname.Name, _, prefix string, argIndex int) string { return fmt.Sprintf("%s%s := args[%d]", prefix, name.UpperCamel, argIndex) diff --git a/ignite/templates/ibc/packet.go b/ignite/templates/ibc/packet.go index 3212471b13..adfd0ffaef 100644 --- a/ignite/templates/ibc/packet.go +++ b/ignite/templates/ibc/packet.go @@ -330,8 +330,13 @@ func protoTxModify(opts *PacketOptions) genny.RunFn { for i, field := range opts.Fields { sendFields = append(sendFields, field.ToProtoField(i+5)) } + + // set address options on signer field + signerField := protoutil.NewField(opts.MsgSigner.Snake, "string", 1) + signerField.Options = append(signerField.Options, protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom())) + sendFields = append(sendFields, - protoutil.NewField(opts.MsgSigner.Snake, "string", 1), + signerField, protoutil.NewField("port", "string", 2), protoutil.NewField("channelID", "string", 3), protoutil.NewField("timeoutTimestamp", "uint64", 4), diff --git a/ignite/templates/message/message.go b/ignite/templates/message/message.go index 233bd27ca5..1ff6e62935 100644 --- a/ignite/templates/message/message.go +++ b/ignite/templates/message/message.go @@ -132,6 +132,7 @@ func protoTxMessageModify(opts *Options) genny.RunFn { } // Prepare the fields and create the messages. creator := protoutil.NewField(opts.MsgSigner.Snake, "string", 1) + creator.Options = append(creator.Options, protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom())) // set the scalar annotation creatorOpt := protoutil.NewOption(typed.MsgSignerOption, opts.MsgSigner.Snake) msgFields := []*proto.NormalField{creator} for i, field := range opts.Fields { diff --git a/ignite/templates/typed/list/list.go b/ignite/templates/typed/list/list.go index 1c53a91814..94ba650cb1 100644 --- a/ignite/templates/typed/list/list.go +++ b/ignite/templates/typed/list/list.go @@ -140,6 +140,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { } // Messages creator := protoutil.NewField(opts.MsgSigner.Snake, "string", 1) + creator.Options = append(creator.Options, protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom())) // set the scalar annotation creatorOpt := protoutil.NewOption(typed.MsgSignerOption, opts.MsgSigner.Snake) createFields := []*proto.NormalField{creator} for i, field := range opts.Fields { diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index 0e1fb0fdfc..6f07016efc 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -621,6 +621,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { } creator := protoutil.NewField(opts.MsgSigner.Snake, "string", 1) + creator.Options = append(creator.Options, protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom())) // set the scalar annotation creatorOpt := protoutil.NewOption(typed.MsgSignerOption, opts.MsgSigner.Snake) commonFields := []*proto.NormalField{creator} commonFields = append(commonFields, index) diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index 0500ffc625..6cbe6a44e2 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -482,6 +482,7 @@ func protoTxModify(opts *typed.Options) genny.RunFn { // Add the messages creator := protoutil.NewField(opts.MsgSigner.Snake, "string", 1) + creator.Options = append(creator.Options, protoutil.NewOption("cosmos_proto.scalar", "cosmos.AddressString", protoutil.Custom())) // set the scalar annotation creatorOpt := protoutil.NewOption(typed.MsgSignerOption, opts.MsgSigner.Snake) fields := []*proto.NormalField{creator} for i, field := range opts.Fields { From d784de4461802c311a43ca3f34e3817b7c53b264 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 20 May 2025 16:44:33 +0200 Subject: [PATCH 5/5] lint --- ignite/templates/field/field.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ignite/templates/field/field.go b/ignite/templates/field/field.go index 276284c904..e0a0002322 100644 --- a/ignite/templates/field/field.go +++ b/ignite/templates/field/field.go @@ -47,6 +47,7 @@ func (f Field) IsSlice() bool { return true case datatype.String, + datatype.Address, datatype.Bool, datatype.Int, datatype.Int64,