Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- [#4687](https://github.com/ignite/cli/pull/4687) Add address type with `scalar` annotations, and add `scalar` type to signer field.

### Bug Fixes

- [#4686](https://github.com/ignite/cli/pull/4686) Filter discovered protos to only messages.
Expand Down
42 changes: 42 additions & 0 deletions ignite/templates/field/datatype/address.go
Original file line number Diff line number Diff line change
@@ -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", 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 := 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"},
}
3 changes: 3 additions & 0 deletions ignite/templates/field/datatype/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -70,6 +72,7 @@ var supportedTypes = map[Name]DataType{
Coin: DataCoin,
Coins: DataCoinSlice,
CoinSliceAlias: DataCoinSlice,
Address: DataAddress,
Custom: DataCustom,
}

Expand Down
5 changes: 5 additions & 0 deletions ignite/templates/field/datatype/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/field/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (f Field) IsSlice() bool {
return true
case
datatype.String,
datatype.Address,
datatype.Bool,
datatype.Int,
datatype.Int64,
Expand Down
7 changes: 6 additions & 1 deletion ignite/templates/ibc/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/typed/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/typed/map/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/typed/singleton/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions integration/other_components/cmd_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestGenerateAnAppWithMessage(t *testing.T) {
"text",
"vote:int",
"like:bool",
"from:address",
"-r",
"foo,bar:int,foobar:bool",
),
Expand Down