diff --git a/api/cosmos/auth/v1beta1/query.pulsar.go b/api/cosmos/auth/v1beta1/query.pulsar.go index 12d8be1490..e645b5154e 100644 --- a/api/cosmos/auth/v1beta1/query.pulsar.go +++ b/api/cosmos/auth/v1beta1/query.pulsar.go @@ -2,9 +2,13 @@ package authv1beta1 import ( + fmt "fmt" + io "io" + reflect "reflect" + sync "sync" + v1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" _ "cosmossdk.io/api/cosmos/query/v1" - fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" @@ -13,9 +17,6 @@ import ( protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" anypb "google.golang.org/protobuf/types/known/anypb" - io "io" - reflect "reflect" - sync "sync" ) var ( diff --git a/api/cosmos/nft/v1beta1/tx.pulsar.go b/api/cosmos/nft/v1beta1/tx.pulsar.go index 246a0a34c1..e3ba0b462e 100644 --- a/api/cosmos/nft/v1beta1/tx.pulsar.go +++ b/api/cosmos/nft/v1beta1/tx.pulsar.go @@ -2,16 +2,17 @@ package nftv1beta1 import ( - _ "cosmossdk.io/api/cosmos/msg/v1" fmt "fmt" + io "io" + reflect "reflect" + sync "sync" + + _ "cosmossdk.io/api/cosmos/msg/v1" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - io "io" - reflect "reflect" - sync "sync" ) var ( diff --git a/api/cosmos/query/v1/query.pulsar.go b/api/cosmos/query/v1/query.pulsar.go index 0c3a26a6f9..bf8c3c9525 100644 --- a/api/cosmos/query/v1/query.pulsar.go +++ b/api/cosmos/query/v1/query.pulsar.go @@ -2,10 +2,11 @@ package queryv1 import ( + reflect "reflect" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" descriptorpb "google.golang.org/protobuf/types/descriptorpb" - reflect "reflect" ) // Code generated by protoc-gen-go. DO NOT EDIT. diff --git a/api/cosmos/tx/v1beta1/service.pulsar.go b/api/cosmos/tx/v1beta1/service.pulsar.go index 8aa6936cb0..2e672c58d9 100644 --- a/api/cosmos/tx/v1beta1/service.pulsar.go +++ b/api/cosmos/tx/v1beta1/service.pulsar.go @@ -2,18 +2,19 @@ package txv1beta1 import ( + fmt "fmt" + io "io" + reflect "reflect" + sync "sync" + v1beta11 "cosmossdk.io/api/cosmos/base/abci/v1beta1" v1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" types "cosmossdk.io/api/tendermint/types" - fmt "fmt" runtime "github.com/cosmos/cosmos-proto/runtime" _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - io "io" - reflect "reflect" - sync "sync" ) var _ protoreflect.List = (*_GetTxsEventRequest_1_list)(nil) diff --git a/client/v2/cli/cmd.go b/client/v2/cli/cmd.go new file mode 100644 index 0000000000..69011c5f5a --- /dev/null +++ b/client/v2/cli/cmd.go @@ -0,0 +1,60 @@ +package cli + +import ( + "errors" + "fmt" + "strings" + + "github.com/spf13/cobra" +) + +// NOTE: this was copied from client/cmd.go to avoid introducing a dependency +// on the v1 client package. + +// validateCmd returns unknown command error or Help display if help flag set +func validateCmd(cmd *cobra.Command, args []string) error { + var unknownCmd string + var skipNext bool + + for _, arg := range args { + // search for help flag + if arg == "--help" || arg == "-h" { + return cmd.Help() + } + + // check if the current arg is a flag + switch { + case len(arg) > 0 && (arg[0] == '-'): + // the next arg should be skipped if the current arg is a + // flag and does not use "=" to assign the flag's value + if !strings.Contains(arg, "=") { + skipNext = true + } else { + skipNext = false + } + case skipNext: + // skip current arg + skipNext = false + case unknownCmd == "": + // unknown command found + // continue searching for help flag + unknownCmd = arg + } + } + + // return the help screen if no unknown command is found + if unknownCmd != "" { + err := fmt.Sprintf("unknown command \"%s\" for \"%s\"", unknownCmd, cmd.CalledAs()) + + // build suggestions for unknown argument + if suggestions := cmd.SuggestionsFor(unknownCmd); len(suggestions) > 0 { + err += "\n\nDid you mean this?\n" + for _, s := range suggestions { + err += fmt.Sprintf("\t%v\n", s) + } + } + return errors.New(err) + } + + return cmd.Help() +} diff --git a/client/v2/cli/flag/address.go b/client/v2/cli/flag/address.go index f2008e4b32..163fbfc9ae 100644 --- a/client/v2/cli/flag/address.go +++ b/client/v2/cli/flag/address.go @@ -3,13 +3,12 @@ package flag import ( "context" - "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" ) type addressStringType struct{} -func (a addressStringType) NewValue(_ context.Context, _ *Builder) pflag.Value { +func (a addressStringType) NewValue(_ context.Context, _ *Builder) Value { return &addressValue{} } @@ -21,8 +20,8 @@ type addressValue struct { value string } -func (a addressValue) Get() protoreflect.Value { - return protoreflect.ValueOfString(a.value) +func (a addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfString(a.value), nil } func (a addressValue) String() string { diff --git a/client/v2/cli/flag/doc.go b/client/v2/cli/flag/doc.go new file mode 100644 index 0000000000..5e8a1f365d --- /dev/null +++ b/client/v2/cli/flag/doc.go @@ -0,0 +1,4 @@ +// Package flag defines functionality for automatically managing command +// line flags as well positional arguments that are based on protobuf message +// fields. +package flag diff --git a/client/v2/cli/flag/duration.go b/client/v2/cli/flag/duration.go index d40f3ad6ea..5e02c00d29 100644 --- a/client/v2/cli/flag/duration.go +++ b/client/v2/cli/flag/duration.go @@ -4,14 +4,13 @@ import ( "context" "time" - "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/known/durationpb" ) type durationType struct{} -func (t durationType) NewValue(context.Context, *Builder) pflag.Value { +func (t durationType) NewValue(context.Context, *Builder) Value { return &durationValue{} } @@ -23,11 +22,11 @@ type durationValue struct { value *durationpb.Duration } -func (t durationValue) Get() protoreflect.Value { - if t.value == nil { - return protoreflect.Value{} +func (a durationValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if a.value == nil { + return protoreflect.Value{}, nil } - return protoreflect.ValueOfMessage(t.value.ProtoReflect()) + return protoreflect.ValueOfMessage(a.value.ProtoReflect()), nil } func (v durationValue) String() string { diff --git a/client/v2/cli/flag/enum.go b/client/v2/cli/flag/enum.go index 65dd6fb813..79e1cba53a 100644 --- a/client/v2/cli/flag/enum.go +++ b/client/v2/cli/flag/enum.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/iancoleman/strcase" - "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" ) @@ -14,7 +13,7 @@ type enumType struct { enum protoreflect.EnumDescriptor } -func (b enumType) NewValue(context.Context, *Builder) pflag.Value { +func (b enumType) NewValue(context.Context, *Builder) Value { val := &enumValue{ enum: b.enum, valMap: map[string]protoreflect.EnumValueDescriptor{}, @@ -41,8 +40,8 @@ type enumValue struct { valMap map[string]protoreflect.EnumValueDescriptor } -func (e enumValue) Get() protoreflect.Value { - return protoreflect.ValueOfEnum(e.value) +func (e enumValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfEnum(e.value), nil } func enumValueName(enum protoreflect.EnumDescriptor, enumValue protoreflect.EnumValueDescriptor) string { diff --git a/client/v2/cli/flag/field.go b/client/v2/cli/flag/field.go index 754a0488c1..93933d04c5 100644 --- a/client/v2/cli/flag/field.go +++ b/client/v2/cli/flag/field.go @@ -2,8 +2,8 @@ package flag import ( "context" - "fmt" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" cosmos_proto "github.com/cosmos/cosmos-proto" "github.com/spf13/pflag" "google.golang.org/protobuf/proto" @@ -12,59 +12,68 @@ import ( "cosmossdk.io/client/v2/internal/util" ) -// FieldValueBinder wraps a flag value in a way that allows it to be bound -// to a particular field in a protobuf message. -type FieldValueBinder interface { - Bind(message protoreflect.Message, field protoreflect.FieldDescriptor) -} - -// Options specifies options for specific flags. -type Options struct { +// namingOptions specifies internal naming options for flags. +type namingOptions struct { // Prefix is a prefix to prepend to all flags. Prefix string } -// AddFieldFlag adds a flag for the provided field to the flag set. -func (b *Builder) AddFieldFlag(ctx context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor, options Options) FieldValueBinder { - if field.Kind() == protoreflect.MessageKind && field.Message().FullName() == "cosmos.base.query.v1beta1.PageRequest" { - return b.bindPageRequest(ctx, flagSet, field) +// addFieldFlag adds a flag for the provided field to the flag set. +func (b *Builder) addFieldFlag(ctx context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor, opts *autocliv1.FlagOptions, options namingOptions) (name string, hasValue HasValue, err error) { + if opts == nil { + opts = &autocliv1.FlagOptions{} } - name := options.Prefix + util.DescriptorKebabName(field) - usage := util.DescriptorDocs(field) - shorthand := "" + if field.Kind() == protoreflect.MessageKind && field.Message().FullName() == "cosmos.base.query.v1beta1.PageRequest" { + hasValue, err := b.bindPageRequest(ctx, flagSet, field) + return "", hasValue, err + } + + name = opts.Name + if name == "" { + name = options.Prefix + util.DescriptorKebabName(field) + } + + usage := opts.Usage + if usage == "" { + usage = util.DescriptorDocs(field) + } + + shorthand := opts.Shorthand + defaultValue := opts.DefaultValue if typ := b.resolveFlagType(field); typ != nil { + if defaultValue == "" { + defaultValue = typ.DefaultValue() + } + val := typ.NewValue(ctx, b) flagSet.AddFlag(&pflag.Flag{ Name: name, Shorthand: shorthand, Usage: usage, - DefValue: typ.DefaultValue(), + DefValue: defaultValue, Value: val, }) - switch val := val.(type) { - case SimpleValue: - return simpleValueBinder{val} - case ListValue: - return listValueBinder{val} - default: - panic(fmt.Errorf("%T does not implement SimpleValue or ListValue", val)) - } + return name, val, nil } + // use the built-in pflag StringP, Int32P, etc. functions + var val HasValue if field.IsList() { - if value := bindSimpleListFlag(flagSet, field.Kind(), name, shorthand, usage); value != nil { - return listValueBinder{value} - } - return nil + val = bindSimpleListFlag(flagSet, field.Kind(), name, shorthand, usage) + + } else { + val = bindSimpleFlag(flagSet, field.Kind(), name, shorthand, usage) } - if value := bindSimpleFlag(flagSet, field.Kind(), name, shorthand, usage); value != nil { - return simpleValueBinder{value} + // This is a bit of hacking around the pflag API, but the + // defaultValue is set in this way because this is much easier than trying + // to parse the string into the types that StringSliceP, Int32P, etc. expect + if defaultValue != "" { + err = flagSet.Set(name, defaultValue) } - - return nil + return name, val, err } func (b *Builder) resolveFlagType(field protoreflect.FieldDescriptor) Type { @@ -105,24 +114,3 @@ func (b *Builder) resolveFlagTypeBasic(field protoreflect.FieldDescriptor) Type return nil } } - -type simpleValueBinder struct { - SimpleValue -} - -func (s simpleValueBinder) Bind(message protoreflect.Message, field protoreflect.FieldDescriptor) { - val := s.Get() - if val.IsValid() { - message.Set(field, val) - } else { - message.Clear(field) - } -} - -type listValueBinder struct { - ListValue -} - -func (s listValueBinder) Bind(message protoreflect.Message, field protoreflect.FieldDescriptor) { - s.AppendTo(message.NewField(field).List()) -} diff --git a/client/v2/cli/flag/list.go b/client/v2/cli/flag/list.go index 28f3b8fe7f..72f84c8be3 100644 --- a/client/v2/cli/flag/list.go +++ b/client/v2/cli/flag/list.go @@ -8,57 +8,51 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" ) -func bindSimpleListFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) ListValue { +func bindSimpleListFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { switch kind { case protoreflect.StringKind: val := flagSet.StringSliceP(name, shorthand, nil, usage) - return listValue(func(list protoreflect.List) { - for _, x := range *val { - list.Append(protoreflect.ValueOfString(x)) - } - }) - case protoreflect.BytesKind: - // TODO - return nil + return newListValue(val, protoreflect.ValueOfString) case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: val := flagSet.UintSliceP(name, shorthand, nil, usage) - return listValue(func(list protoreflect.List) { - for _, x := range *val { - list.Append(protoreflect.ValueOfUint64(uint64(x))) - } - }) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, - protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := flagSet.IntSliceP(name, shorthand, nil, usage) - return listValue(func(list protoreflect.List) { - for _, x := range *val { - list.Append(protoreflect.ValueOfInt64(int64(x))) - } - }) + return newListValue(val, func(x uint) protoreflect.Value { return protoreflect.ValueOfUint64(uint64(x)) }) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := flagSet.Int32SliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := flagSet.Int64SliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfInt64) case protoreflect.BoolKind: val := flagSet.BoolSliceP(name, shorthand, nil, usage) - return listValue(func(list protoreflect.List) { - for _, x := range *val { - list.Append(protoreflect.ValueOfBool(x)) - } - }) + return newListValue(val, protoreflect.ValueOfBool) default: return nil } } -type listValue func(protoreflect.List) +type listValue[T any] struct { + array *[]T + toProtoreflectValue func(T) protoreflect.Value +} -func (f listValue) AppendTo(list protoreflect.List) { - f(list) +func newListValue[T any](array *[]T, toProtoreflectValue func(T) protoreflect.Value) listValue[T] { + return listValue[T]{array: array, toProtoreflectValue: toProtoreflectValue} +} + +func (v listValue[T]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + list := mutable.List() + for _, x := range *v.array { + list.Append(v.toProtoreflectValue(x)) + } + return mutable, nil } type compositeListType struct { simpleType Type } -func (t compositeListType) NewValue(ctx context.Context, opts *Builder) pflag.Value { +func (t compositeListType) NewValue(ctx context.Context, opts *Builder) Value { return &compositeListValue{ simpleType: t.simpleType, values: nil, @@ -78,13 +72,15 @@ type compositeListValue struct { opts *Builder } -func (c compositeListValue) AppendTo(list protoreflect.List) { +func (c *compositeListValue) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + list := mutable.List() for _, value := range c.values { list.Append(value) } + return mutable, nil } -func (c compositeListValue) String() string { +func (c *compositeListValue) String() string { if len(c.values) == 0 { return "" } @@ -98,10 +94,14 @@ func (c *compositeListValue) Set(val string) error { if err != nil { return err } - c.values = append(c.values, simpleVal.(SimpleValue).Get()) + v, err := simpleVal.Get(protoreflect.Value{}) + if err != nil { + return err + } + c.values = append(c.values, v) return nil } -func (c compositeListValue) Type() string { +func (c *compositeListValue) Type() string { return fmt.Sprintf("%s (repeated)", c.simpleType.NewValue(c.ctx, c.opts).Type()) } diff --git a/client/v2/cli/flag/message.go b/client/v2/cli/flag/message.go index 1ad6d8b1be..6d07e3564a 100644 --- a/client/v2/cli/flag/message.go +++ b/client/v2/cli/flag/message.go @@ -1,64 +1,99 @@ package flag import ( - "context" "fmt" + "github.com/spf13/cobra" "github.com/spf13/pflag" - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" - - "cosmossdk.io/client/v2/internal/util" ) -type jsonMessageFlagType struct { - messageDesc protoreflect.MessageDescriptor +// MessageBinder binds multiple flags in a flag set to a protobuf message. +type MessageBinder struct { + CobraArgs cobra.PositionalArgs + + positionalFlagSet *pflag.FlagSet + positionalArgs []fieldBinding + hasVarargs bool + + flagBindings []fieldBinding + messageType protoreflect.MessageType } -func (j jsonMessageFlagType) NewValue(_ context.Context, builder *Builder) pflag.Value { - return &jsonMessageFlagValue{ - messageType: util.ResolveMessageType(builder.TypeResolver, j.messageDesc), - jsonMarshalOptions: protojson.MarshalOptions{Resolver: builder.TypeResolver}, - jsonUnmarshalOptions: protojson.UnmarshalOptions{Resolver: builder.TypeResolver}, - } +// BuildMessage builds and returns a new message for the bound flags. +func (m MessageBinder) BuildMessage(positionalArgs []string) (protoreflect.Message, error) { + msg := m.messageType.New() + err := m.Bind(msg, positionalArgs) + return msg, err } -func (j jsonMessageFlagType) DefaultValue() string { - return "" -} +// Bind binds the flag values to an existing protobuf message. +func (m MessageBinder) Bind(msg protoreflect.Message, positionalArgs []string) error { + // first set positional args in the positional arg flag set + n := len(positionalArgs) + for i := range m.positionalArgs { + if i >= n { + panic("unexpected: validate args should have caught this") + } -type jsonMessageFlagValue struct { - jsonMarshalOptions protojson.MarshalOptions - jsonUnmarshalOptions protojson.UnmarshalOptions - messageType protoreflect.MessageType - message proto.Message -} - -func (j jsonMessageFlagValue) Get() protoreflect.Value { - if j.message == nil { - return protoreflect.Value{} - } - return protoreflect.ValueOfMessage(j.message.ProtoReflect()) -} - -func (j jsonMessageFlagValue) String() string { - if j.message == nil { - return "" + name := fmt.Sprintf("%d", i) + if i == n-1 && m.hasVarargs { + for _, v := range positionalArgs[i:] { + err := m.positionalFlagSet.Set(name, v) + if err != nil { + return err + } + } + } else { + err := m.positionalFlagSet.Set(name, positionalArgs[i]) + if err != nil { + return err + } + } } - bz, err := j.jsonMarshalOptions.Marshal(j.message) + // bind positional arg values to the message + for _, arg := range m.positionalArgs { + err := arg.bind(msg) + if err != nil { + return err + } + } + + // bind flag values to the message + for _, binding := range m.flagBindings { + err := binding.bind(msg) + if err != nil { + return err + } + } + + return nil +} + +// Get calls BuildMessage and wraps the result in a protoreflect.Value. +func (m MessageBinder) Get(protoreflect.Value) (protoreflect.Value, error) { + msg, err := m.BuildMessage(nil) + return protoreflect.ValueOfMessage(msg), err +} + +type fieldBinding struct { + hasValue HasValue + field protoreflect.FieldDescriptor +} + +func (f fieldBinding) bind(msg protoreflect.Message) error { + field := f.field + val, err := f.hasValue.Get(msg.NewField(field)) if err != nil { - return err.Error() + return err } - return string(bz) -} - -func (j *jsonMessageFlagValue) Set(s string) error { - j.message = j.messageType.New().Interface() - return j.jsonUnmarshalOptions.Unmarshal([]byte(s), j.message) -} - -func (j jsonMessageFlagValue) Type() string { - return fmt.Sprintf("%s (json)", j.messageType.Descriptor().FullName()) + kind := f.field.Kind() + if !(field.IsList() || + field.IsMap() || + kind == protoreflect.MessageKind || + kind == protoreflect.GroupKind) { + msg.Set(f.field, val) + } + return nil } diff --git a/client/v2/cli/flag/message_json.go b/client/v2/cli/flag/message_json.go new file mode 100644 index 0000000000..69b0d69fea --- /dev/null +++ b/client/v2/cli/flag/message_json.go @@ -0,0 +1,63 @@ +package flag + +import ( + "context" + "fmt" + + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/client/v2/internal/util" +) + +type jsonMessageFlagType struct { + messageDesc protoreflect.MessageDescriptor +} + +func (j jsonMessageFlagType) NewValue(_ context.Context, builder *Builder) Value { + return &jsonMessageFlagValue{ + messageType: util.ResolveMessageType(builder.TypeResolver, j.messageDesc), + jsonMarshalOptions: protojson.MarshalOptions{Resolver: builder.TypeResolver}, + jsonUnmarshalOptions: protojson.UnmarshalOptions{Resolver: builder.TypeResolver}, + } +} + +func (j jsonMessageFlagType) DefaultValue() string { + return "" +} + +type jsonMessageFlagValue struct { + jsonMarshalOptions protojson.MarshalOptions + jsonUnmarshalOptions protojson.UnmarshalOptions + messageType protoreflect.MessageType + message proto.Message +} + +func (j *jsonMessageFlagValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if j.message == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(j.message.ProtoReflect()), nil +} + +func (j *jsonMessageFlagValue) String() string { + if j.message == nil { + return "" + } + + bz, err := j.jsonMarshalOptions.Marshal(j.message) + if err != nil { + return err.Error() + } + return string(bz) +} + +func (j *jsonMessageFlagValue) Set(s string) error { + j.message = j.messageType.New().Interface() + return j.jsonUnmarshalOptions.Unmarshal([]byte(s), j.message) +} + +func (j *jsonMessageFlagValue) Type() string { + return fmt.Sprintf("%s (json)", j.messageType.Descriptor().FullName()) +} diff --git a/client/v2/cli/flag/pagination.go b/client/v2/cli/flag/pagination.go index 2e8b98aef0..31d5316251 100644 --- a/client/v2/cli/flag/pagination.go +++ b/client/v2/cli/flag/pagination.go @@ -3,18 +3,19 @@ package flag import ( "context" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/client/v2/internal/util" ) -func (b *Builder) bindPageRequest(ctx context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor) FieldValueBinder { - handler := b.AddMessageFlags( +func (b *Builder) bindPageRequest(ctx context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor) (HasValue, error) { + return b.addMessageFlags( ctx, flagSet, util.ResolveMessageType(b.TypeResolver, field.Message()), - Options{Prefix: "page-"}, + &autocliv1.RpcCommandOptions{}, + namingOptions{Prefix: "page-"}, ) - return simpleValueBinder{handler} } diff --git a/client/v2/cli/flag/register.go b/client/v2/cli/flag/register.go index c0d15c17d4..cc18df69b6 100644 --- a/client/v2/cli/flag/register.go +++ b/client/v2/cli/flag/register.go @@ -4,56 +4,109 @@ import ( "context" "fmt" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" ) +func (b *Builder) AddMessageFlags(ctx context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions) (*MessageBinder, error) { + return b.addMessageFlags(ctx, flagSet, messageType, commandOptions, namingOptions{}) +} + // AddMessageFlags adds flags for each field in the message to the flag set. -func (b *Builder) AddMessageFlags(ctx context.Context, set *pflag.FlagSet, messageType protoreflect.MessageType, options Options) *MessageBinder { +func (b *Builder) addMessageFlags(ctx context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions, options namingOptions) (*MessageBinder, error) { fields := messageType.Descriptor().Fields() numFields := fields.Len() handler := &MessageBinder{ messageType: messageType, } + + isPositional := map[string]bool{} + hasVarargs := false + n := len(commandOptions.PositionalArgs) + // positional args are also parsed using a FlagSet so that we can reuse all the same parsers + handler.positionalFlagSet = pflag.NewFlagSet("positional", pflag.ContinueOnError) + for i, arg := range commandOptions.PositionalArgs { + isPositional[arg.ProtoField] = true + + field := fields.ByName(protoreflect.Name(arg.ProtoField)) + if field == nil { + return nil, fmt.Errorf("can't find field %s on %s", arg.ProtoField, messageType.Descriptor().FullName()) + } + + if arg.Varargs { + if i != n-1 { + return nil, fmt.Errorf("varargs positional argument %s must be the last argument", arg.ProtoField) + } + + hasVarargs = true + } + + _, hasValue, err := b.addFieldFlag( + ctx, + handler.positionalFlagSet, + field, + &autocliv1.FlagOptions{Name: fmt.Sprintf("%d", i)}, + namingOptions{}, + ) + if err != nil { + return nil, err + } + + handler.positionalArgs = append(handler.positionalArgs, fieldBinding{ + field: field, + hasValue: hasValue, + }) + } + + if hasVarargs { + handler.CobraArgs = cobra.MinimumNArgs(n) + handler.hasVarargs = true + } else { + handler.CobraArgs = cobra.ExactArgs(n) + } + + // validate flag options + for name := range commandOptions.FlagOptions { + if fields.ByName(protoreflect.Name(name)) == nil { + return nil, fmt.Errorf("can't find field %s on %s specified as a flag", name, messageType.Descriptor().FullName()) + } + } + + flagOptsByFlagName := map[string]*autocliv1.FlagOptions{} for i := 0; i < numFields; i++ { field := fields.Get(i) - binder := b.AddFieldFlag(ctx, set, field, options) - if binder == nil { - fmt.Printf("unable to bind field %s to a flag, support will be added soon\n", field) + if isPositional[string(field.Name())] { continue } - handler.flagFieldPairs = append(handler.flagFieldPairs, struct { - binder FieldValueBinder - field protoreflect.FieldDescriptor - }{binder: binder, field: field}) + + flagOpts := commandOptions.FlagOptions[string(field.Name())] + name, hasValue, err := b.addFieldFlag(ctx, flagSet, field, flagOpts, options) + flagOptsByFlagName[name] = flagOpts + if err != nil { + return nil, err + } + + handler.flagBindings = append(handler.flagBindings, fieldBinding{ + hasValue: hasValue, + field: field, + }) } - return handler -} -// MessageBinder binds multiple flags in a flag set to a protobuf message. -type MessageBinder struct { - flagFieldPairs []struct { - binder FieldValueBinder - field protoreflect.FieldDescriptor - } - messageType protoreflect.MessageType -} + flagSet.VisitAll(func(flag *pflag.Flag) { + opts := flagOptsByFlagName[flag.Name] + if opts != nil { + // This is a bit of hacking around the pflag API, but + // we need to set these options here using Flag.VisitAll because the flag + // constructors that pflag gives us (StringP, Int32P, etc.) do not + // actually return the *Flag instance + flag.Deprecated = opts.Deprecated + flag.ShorthandDeprecated = opts.ShorthandDeprecated + flag.Hidden = opts.Hidden + flag.NoOptDefVal = opts.NoOptDefaultValue + } + }) -// BuildMessage builds and returns a new message for the bound flags. -func (m MessageBinder) BuildMessage() protoreflect.Message { - msg := m.messageType.New() - m.Bind(msg) - return msg -} - -// Bind binds the flag values to an existing protobuf message. -func (m MessageBinder) Bind(msg protoreflect.Message) { - for _, pair := range m.flagFieldPairs { - pair.binder.Bind(msg, pair.field) - } -} - -// Get calls BuildMessage and wraps the result in a protoreflect.Value. -func (m MessageBinder) Get() protoreflect.Value { - return protoreflect.ValueOfMessage(m.BuildMessage()) + return handler, nil } diff --git a/client/v2/cli/flag/simple.go b/client/v2/cli/flag/simple.go index 6caf25c6ca..d4ed6d4464 100644 --- a/client/v2/cli/flag/simple.go +++ b/client/v2/cli/flag/simple.go @@ -5,50 +5,43 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" ) -func bindSimpleFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) SimpleValue { +func bindSimpleFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { switch kind { case protoreflect.BytesKind: val := flagSet.BytesBase64P(name, shorthand, nil, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfBytes(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfBytes) case protoreflect.StringKind: val := flagSet.StringP(name, shorthand, "", usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfString(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfString) case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: val := flagSet.Uint32P(name, shorthand, 0, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfUint32(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfUint32) case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: val := flagSet.Uint64P(name, shorthand, 0, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfUint64(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfUint64) case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: val := flagSet.Int32P(name, shorthand, 0, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfInt32(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfInt32) case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: val := flagSet.Int64P(name, shorthand, 0, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfInt64(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfInt64) case protoreflect.BoolKind: val := flagSet.BoolP(name, shorthand, false, usage) - return simpleValue(func() protoreflect.Value { - return protoreflect.ValueOfBool(*val) - }) + return newSimpleValue(val, protoreflect.ValueOfBool) default: return nil } } -type simpleValue func() protoreflect.Value - -func (f simpleValue) Get() protoreflect.Value { - return f() +type simpleValue[T any] struct { + val *T + toProtoreflectValue func(T) protoreflect.Value +} + +func newSimpleValue[T any](val *T, toProtoreflectValue func(T) protoreflect.Value) HasValue { + return simpleValue[T]{val: val, toProtoreflectValue: toProtoreflectValue} +} + +func (v simpleValue[T]) Get(protoreflect.Value) (protoreflect.Value, error) { + return v.toProtoreflectValue(*v.val), nil } diff --git a/client/v2/cli/flag/timestamp.go b/client/v2/cli/flag/timestamp.go index e9386bad3b..799dab4f32 100644 --- a/client/v2/cli/flag/timestamp.go +++ b/client/v2/cli/flag/timestamp.go @@ -4,14 +4,13 @@ import ( "context" "time" - "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/known/timestamppb" ) type timestampType struct{} -func (t timestampType) NewValue(context.Context, *Builder) pflag.Value { +func (t timestampType) NewValue(context.Context, *Builder) Value { return ×tampValue{} } @@ -23,11 +22,11 @@ type timestampValue struct { value *timestamppb.Timestamp } -func (t timestampValue) Get() protoreflect.Value { +func (t timestampValue) Get(protoreflect.Value) (protoreflect.Value, error) { if t.value == nil { - return protoreflect.Value{} + return protoreflect.Value{}, nil } - return protoreflect.ValueOfMessage(t.value.ProtoReflect()) + return protoreflect.ValueOfMessage(t.value.ProtoReflect()), nil } func (v timestampValue) String() string { diff --git a/client/v2/cli/flag/type.go b/client/v2/cli/flag/type.go index 62fce2a6bc..a0e79b553d 100644 --- a/client/v2/cli/flag/type.go +++ b/client/v2/cli/flag/type.go @@ -2,15 +2,13 @@ package flag import ( "context" - - "github.com/spf13/pflag" ) // Type specifies a custom flag type. type Type interface { // NewValue returns a new pflag.Value which must also implement either // SimpleValue or ListValue. - NewValue(context.Context, *Builder) pflag.Value + NewValue(context.Context, *Builder) Value // DefaultValue is the default value for this type. DefaultValue() string diff --git a/client/v2/cli/flag/value.go b/client/v2/cli/flag/value.go index 304139e642..e42c524d78 100644 --- a/client/v2/cli/flag/value.go +++ b/client/v2/cli/flag/value.go @@ -1,17 +1,21 @@ package flag import ( + "github.com/spf13/pflag" "google.golang.org/protobuf/reflect/protoreflect" ) -// SimpleValue wraps a simple (non-list and non-map) protobuf value. -type SimpleValue interface { - // Get returns the value. - Get() protoreflect.Value +// Value represents a single pflag.Value value. +type Value interface { + pflag.Value + HasValue } -// ListValue wraps a protobuf list/repeating value. -type ListValue interface { - // AppendTo appends the values to the provided list. - AppendTo(protoreflect.List) +// HasValue wraps a reference to a protobuf value. +type HasValue interface { + // Get gets the value of the protobuf value reference and returns that value + // or an error. For composite protoreflect.Value types such as messages, + // lists and maps, a mutable reference to the value of field obtained with + // protoreflect.Message.NewField should be passed as the newFieldValue parameter. + Get(newFieldValue protoreflect.Value) (protoreflect.Value, error) } diff --git a/client/v2/cli/query.go b/client/v2/cli/query.go index b3bea2345e..a345ad1383 100644 --- a/client/v2/cli/query.go +++ b/client/v2/cli/query.go @@ -3,54 +3,156 @@ package cli import ( "fmt" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "github.com/iancoleman/strcase" "github.com/spf13/cobra" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" - "cosmossdk.io/client/v2/cli/flag" "cosmossdk.io/client/v2/internal/util" ) +// BuildQueryCommand builds the query commands for all the provided modules. If a custom command is provided for a +// module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client +// with a more customized experience if a binary with custom commands is downloaded. +func (b *Builder) BuildQueryCommand(moduleOptions map[string]*autocliv1.ModuleOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error) { + queryCmd := topLevelCmd("query", "Querying subcommands") + queryCmd.Aliases = []string{"q"} + for moduleName, modOpts := range moduleOptions { + if customCmds[moduleName] != nil { + // custom commands get added lower down + continue + } + + queryCmdDesc := modOpts.Query + if queryCmdDesc != nil { + cmd, err := b.BuildModuleQueryCommand(moduleName, queryCmdDesc) + if err != nil { + return nil, err + } + + queryCmd.AddCommand(cmd) + } + } + + for _, cmd := range customCmds { + queryCmd.AddCommand(cmd) + } + + return queryCmd, nil +} + +// BuildModuleQueryCommand builds the query command for a single module. +func (b *Builder) BuildModuleQueryCommand(moduleName string, cmdDescriptor *autocliv1.ServiceCommandDescriptor) (*cobra.Command, error) { + cmd := topLevelCmd(moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) + + err := b.AddQueryServiceCommands(cmd, cmdDescriptor) + + return cmd, err +} + // AddQueryServiceCommands adds a sub-command to the provided command for each -// method in the specified service and returns the command. -func (b *Builder) AddQueryServiceCommands(command *cobra.Command, serviceName protoreflect.FullName) *cobra.Command { +// method in the specified service and returns the command. This can be used in +// order to add auto-generated commands to an existing command. +func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error { resolver := b.FileResolver if resolver == nil { resolver = protoregistry.GlobalFiles } - descriptor, err := resolver.FindDescriptorByName(serviceName) + descriptor, err := resolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service)) if err != nil { - panic(err) + return fmt.Errorf("can't find service %s: %v", cmdDescriptor.Service, err) } service := descriptor.(protoreflect.ServiceDescriptor) methods := service.Methods() + + rpcOptMap := map[protoreflect.Name]*autocliv1.RpcCommandOptions{} + for _, option := range cmdDescriptor.RpcCommandOptions { + name := protoreflect.Name(option.RpcMethod) + rpcOptMap[name] = option + // make sure method exists + if m := methods.ByName(name); m == nil { + return fmt.Errorf("rpc method %s not found for service %s", name, service.FullName()) + } + } + n := methods.Len() for i := 0; i < n; i++ { - cmd := b.CreateQueryMethodCommand(methods.Get(i)) - command.AddCommand(cmd) + methodDescriptor := methods.Get(i) + methodOpts := rpcOptMap[methodDescriptor.Name()] + methodCmd, err := b.BuildQueryMethodCommand(methodDescriptor, methodOpts) + if err != nil { + return err + } + + if methodCmd != nil { + cmd.AddCommand(methodCmd) + } } - return command + + for cmdName, subCmdDesc := range cmdDescriptor.SubCommands { + subCmd := topLevelCmd(cmdName, fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service)) + err = b.AddQueryServiceCommands(subCmd, subCmdDesc) + if err != nil { + return err + } + + cmd.AddCommand(subCmd) + } + + return nil } -// CreateQueryMethodCommand creates a gRPC query command for the given service method. -func (b *Builder) CreateQueryMethodCommand(descriptor protoreflect.MethodDescriptor) *cobra.Command { +// BuildQueryMethodCommand creates a gRPC query command for the given service method. This can be used to auto-generate +// just a single command for a single service rpc method. +func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { + if options == nil { + // use the defaults + options = &autocliv1.RpcCommandOptions{} + } + + if options.Skip { + return nil, nil + } + serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) - docs := util.DescriptorDocs(descriptor) + + long := options.Long + if long == "" { + long = util.DescriptorDocs(descriptor) + } + getClientConn := b.GetClientConn methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) inputDesc := descriptor.Input() inputType := util.ResolveMessageType(b.TypeResolver, inputDesc) outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) - cmd := &cobra.Command{ - Use: protoNameToCliName(descriptor.Name()), - Long: docs, + + use := options.Use + if use == "" { + use = protoNameToCliName(descriptor.Name()) } - binder := b.AddMessageFlags(cmd.Context(), cmd.Flags(), inputType, flag.Options{}) + cmd := &cobra.Command{ + Use: use, + Long: long, + Short: options.Short, + Example: options.Example, + Aliases: options.Alias, + SuggestFor: options.SuggestFor, + Deprecated: options.Deprecated, + Version: options.Version, + } + + binder, err := b.AddMessageFlags(cmd.Context(), cmd.Flags(), inputType, options) + if err != nil { + return nil, err + } + + cmd.Args = binder.CobraArgs jsonMarshalOptions := protojson.MarshalOptions{ Indent: " ", @@ -63,9 +165,13 @@ func (b *Builder) CreateQueryMethodCommand(descriptor protoreflect.MethodDescrip cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() clientConn := getClientConn(ctx) - input := binder.BuildMessage() + input, err := binder.BuildMessage(args) + if err != nil { + return err + } + output := outputType.New() - err := clientConn.Invoke(ctx, methodName, input.Interface(), output.Interface()) + err = clientConn.Invoke(ctx, methodName, input.Interface(), output.Interface()) if err != nil { return err } @@ -79,9 +185,19 @@ func (b *Builder) CreateQueryMethodCommand(descriptor protoreflect.MethodDescrip return err } - return cmd + return cmd, nil } func protoNameToCliName(name protoreflect.Name) string { return strcase.ToKebab(string(name)) } + +func topLevelCmd(use, short string) *cobra.Command { + return &cobra.Command{ + Use: use, + Short: short, + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: validateCmd, + } +} diff --git a/client/v2/cli/query_test.go b/client/v2/cli/query_test.go index f4b492edda..3d4c71550c 100644 --- a/client/v2/cli/query_test.go +++ b/client/v2/cli/query_test.go @@ -4,12 +4,13 @@ import ( "bytes" "context" "net" + "strings" "testing" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/testing/protocmp" "gotest.tools/v3/assert" "gotest.tools/v3/golden" @@ -17,16 +18,100 @@ import ( "cosmossdk.io/client/v2/internal/testpb" ) +var testCmdDesc = &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Use: "echo [pos1] [pos2] [pos3...]", + Version: "1.0", + Alias: []string{"e"}, + SuggestFor: []string{"eco"}, + Example: "echo 1 abc {}", + Short: "echo echos the value provided by the user", + Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "positional1", + }, + { + ProtoField: "positional2", + }, + { + ProtoField: "positional3_varargs", + Varargs: true, + }, + }, + FlagOptions: map[string]*autocliv1.FlagOptions{ + "u32": { + Name: "uint32", + Shorthand: "u", + Usage: "some random uint32", + }, + "i32": { + Usage: "some random int32", + DefaultValue: "3", + }, + "u64": { + Usage: "some random uint64", + NoOptDefaultValue: "5", + }, + "deprecated_field": { + Deprecated: "don't use this", + }, + "shorthand_deprecated_field": { + Shorthand: "s", + Deprecated: "bad idea", + }, + "hidden_bool": { + Hidden: true, + }, + }, + }, + }, + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + // we test the sub-command functionality using the same service with different options + "deprecatedecho": { + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Deprecated: "don't use this", + }, + }, + }, + "skipecho": { + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Skip: true, + }, + }, + }, + }, +} + func testExec(t *testing.T, args ...string) *testClientConn { server := grpc.NewServer() testpb.RegisterQueryServer(server, &testEchoServer{}) listener, err := net.Listen("tcp", "127.0.0.1:0") assert.NilError(t, err) - go server.Serve(listener) + go func() { + err := server.Serve(listener) + if err != nil { + panic(err) + } + }() defer server.GracefulStop() clientConn, err := grpc.Dial(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) assert.NilError(t, err) - defer clientConn.Close() + defer func() { + err := clientConn.Close() + if err != nil { + panic(err) + } + }() conn := &testClientConn{ ClientConn: clientConn, @@ -38,21 +123,26 @@ func testExec(t *testing.T, args ...string) *testClientConn { return conn }, } - cmd := b.AddQueryServiceCommands(&cobra.Command{Use: "test"}, protoreflect.FullName(testpb.Query_ServiceDesc.ServiceName)) + cmd, err := b.BuildModuleQueryCommand("test", testCmdDesc) + assert.NilError(t, err) cmd.SetArgs(args) cmd.SetOut(conn.out) assert.NilError(t, cmd.Execute()) return conn } -func TestEcho(t *testing.T) { +func TestEverything(t *testing.T) { conn := testExec(t, "echo", + "1", + "abc", + `{"denom":"foo","amount":"1234"}`, + `{"denom":"bar","amount":"4321"}`, "--a-bool", "--an-enum", "one", "--a-message", `{"bar":"abc", "baz":-3}`, "--duration", "4h3s", - "--u-32", "27", + "--uint32", "27", "--u-64", "3267246890", "--i-32", "-253", "--i-64", "-234602347", @@ -86,9 +176,106 @@ func TestEcho(t *testing.T) { assert.DeepEqual(t, conn.lastRequest, conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) } +func TestOptions(t *testing.T) { + conn := testExec(t, + "echo", + "1", "abc", `{"denom":"foo","amount":"1"}`, + "-u", "27", // shorthand + "--u-64", // no opt default value + ) + lastReq := conn.lastRequest.(*testpb.EchoRequest) + assert.Equal(t, uint32(27), lastReq.U32) // shorthand got set + assert.Equal(t, int32(3), lastReq.I32) // default value got set + assert.Equal(t, uint64(5), lastReq.U64) // no opt default value got set +} + func TestHelp(t *testing.T) { - conn := testExec(t, "echo", "-h") - golden.Assert(t, conn.out.String(), "help.golden") + conn := testExec(t, "-h") + golden.Assert(t, conn.out.String(), "help-toplevel.golden") + + conn = testExec(t, "echo", "-h") + golden.Assert(t, conn.out.String(), "help-echo.golden") + + conn = testExec(t, "deprecatedecho", "echo", "-h") + golden.Assert(t, conn.out.String(), "help-deprecated.golden") + + conn = testExec(t, "skipecho", "-h") + golden.Assert(t, conn.out.String(), "help-skip.golden") +} + +func TestDeprecated(t *testing.T) { + conn := testExec(t, "echo", + "1", "abc", `{}`, + "--deprecated-field", "foo") + assert.Assert(t, strings.Contains(conn.out.String(), "--deprecated-field has been deprecated")) + + conn = testExec(t, "echo", + "1", "abc", `{}`, + "-s", "foo") + assert.Assert(t, strings.Contains(conn.out.String(), "--shorthand-deprecated-field has been deprecated")) +} + +func TestBuildCustomQueryCommand(t *testing.T) { + b := &Builder{} + customCommandCalled := false + cmd, err := b.BuildQueryCommand(map[string]*autocliv1.ModuleOptions{ + "test": { + Query: testCmdDesc, + }, + }, map[string]*cobra.Command{ + "test": {Use: "test", Run: func(cmd *cobra.Command, args []string) { + customCommandCalled = true + }}, + }) + assert.NilError(t, err) + cmd.SetArgs([]string{"test", "query"}) + assert.NilError(t, cmd.Execute()) + assert.Assert(t, customCommandCalled) +} + +func TestNotFoundErrors(t *testing.T) { + b := &Builder{} + + // bad service + _, err := b.BuildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{Service: "foo"}) + assert.ErrorContains(t, err, "can't find service foo") + + // bad method + _, err = b.BuildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "bar"}}, + }) + assert.ErrorContains(t, err, "rpc method bar not found") + + // bad positional field + _, err = b.BuildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "foo", + }, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field foo") + + // bad flag field + _, err = b.BuildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + FlagOptions: map[string]*autocliv1.FlagOptions{ + "baz": {}, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field baz") } type testClientConn struct { diff --git a/client/v2/cli/testdata/help-deprecated.golden b/client/v2/cli/testdata/help-deprecated.golden new file mode 100644 index 0000000000..110b881293 --- /dev/null +++ b/client/v2/cli/testdata/help-deprecated.golden @@ -0,0 +1,36 @@ +Command "echo" is deprecated, don't use this +Usage: + test deprecatedecho echo [flags] + +Flags: + --a-bool + --a-coin cosmos.base.v1beta1.Coin (json) + --a-message testpb.AMessage (json) + --an-address bech32 account address key name + --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) + --bools bools (default []) + --bz bytesBase64 + --deprecated-field string + --duration duration + --durations duration (repeated) + --enums Enum (unspecified | one | two | five | neg-three) (repeated) + -h, --help help for echo + --hidden-bool + --i-32 int32 + --i-64 int + --page-count-total + --page-key bytesBase64 + --page-limit uint + --page-offset uint + --page-reverse + --positional-1 int32 + --positional-2 string + --positional-3-varargs cosmos.base.v1beta1.Coin (json) (repeated) + --shorthand-deprecated-field string + --some-messages testpb.AMessage (json) (repeated) + --str string + --strings strings + --timestamp timestamp (RFC 3339) + --u-32 uint32 + --u-64 uint + --uints uints (default []) diff --git a/client/v2/cli/testdata/help-echo.golden b/client/v2/cli/testdata/help-echo.golden new file mode 100644 index 0000000000..a129553346 --- /dev/null +++ b/client/v2/cli/testdata/help-echo.golden @@ -0,0 +1,40 @@ +echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments + +Usage: + test echo [pos1] [pos2] [pos3...] [flags] + +Aliases: + echo, e + +Examples: +echo 1 abc {} + +Flags: + --a-bool + --a-coin cosmos.base.v1beta1.Coin (json) + --a-message testpb.AMessage (json) + --an-address bech32 account address key name + --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) + --bools bools (default []) + --bz bytesBase64 + --deprecated-field string (DEPRECATED: don't use this) + --duration duration + --durations duration (repeated) + --enums Enum (unspecified | one | two | five | neg-three) (repeated) + -h, --help help for echo + --i-32 int32 some random int32 + --i-64 int + --page-count-total + --page-key bytesBase64 + --page-limit uint + --page-offset uint + --page-reverse + -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) + --some-messages testpb.AMessage (json) (repeated) + --str string + --strings strings + --timestamp timestamp (RFC 3339) + --u-64 uint[=5] some random uint64 + -u, --uint32 uint32 some random uint32 + --uints uints (default []) + -v, --version version for echo diff --git a/client/v2/cli/testdata/help-skip.golden b/client/v2/cli/testdata/help-skip.golden new file mode 100644 index 0000000000..a85dbef695 --- /dev/null +++ b/client/v2/cli/testdata/help-skip.golden @@ -0,0 +1,7 @@ +Querying commands for the testpb.Query service + +Usage: + test skipecho [flags] + +Flags: + -h, --help help for skipecho diff --git a/client/v2/cli/testdata/help-toplevel.golden b/client/v2/cli/testdata/help-toplevel.golden new file mode 100644 index 0000000000..7bab88a556 --- /dev/null +++ b/client/v2/cli/testdata/help-toplevel.golden @@ -0,0 +1,17 @@ +Querying commands for the test module + +Usage: + test [flags] + test [command] + +Available Commands: + completion Generate the autocompletion script for the specified shell + deprecatedecho Querying commands for the testpb.Query service + echo echo echos the value provided by the user + help Help about any command + skipecho Querying commands for the testpb.Query service + +Flags: + -h, --help help for test + +Use "test [command] --help" for more information about a command. diff --git a/client/v2/cli/testdata/help.golden b/client/v2/cli/testdata/help.golden index bcb9c087fd..a129553346 100644 --- a/client/v2/cli/testdata/help.golden +++ b/client/v2/cli/testdata/help.golden @@ -1,5 +1,13 @@ +echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments + Usage: - test echo [flags] + test echo [pos1] [pos2] [pos3...] [flags] + +Aliases: + echo, e + +Examples: +echo 1 abc {} Flags: --a-bool @@ -9,21 +17,24 @@ Flags: --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) --bools bools (default []) --bz bytesBase64 + --deprecated-field string (DEPRECATED: don't use this) --duration duration --durations duration (repeated) --enums Enum (unspecified | one | two | five | neg-three) (repeated) -h, --help help for echo - --i-32 int32 + --i-32 int32 some random int32 --i-64 int --page-count-total --page-key bytesBase64 --page-limit uint --page-offset uint --page-reverse + -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) --some-messages testpb.AMessage (json) (repeated) --str string --strings strings --timestamp timestamp (RFC 3339) - --u-32 uint32 - --u-64 uint + --u-64 uint[=5] some random uint64 + -u, --uint32 uint32 some random uint32 --uints uints (default []) + -v, --version version for echo diff --git a/client/v2/internal/testpb/query.proto b/client/v2/internal/testpb/query.proto index 5bb49a0b2a..dd5b9b67e5 100644 --- a/client/v2/internal/testpb/query.proto +++ b/client/v2/internal/testpb/query.proto @@ -15,34 +15,42 @@ service Query { message EchoRequest { // u32 is an uint32 - uint32 u32 = 1; - uint64 u64 = 2; - string str = 3; - bytes bz = 4; - google.protobuf.Timestamp timestamp = 5; - google.protobuf.Duration duration = 6; - int32 i32 = 7; - int64 i64 = 10; - bool a_bool = 15; - Enum an_enum = 16; - AMessage a_message = 17; - cosmos.base.v1beta1.Coin a_coin = 18; + uint32 u32 = 1; + uint64 u64 = 2; + string str = 3; + bytes bz = 4; + google.protobuf.Timestamp timestamp = 5; + google.protobuf.Duration duration = 6; + int32 i32 = 7; + int64 i64 = 10; + bool a_bool = 15; + Enum an_enum = 16; + AMessage a_message = 17; + cosmos.base.v1beta1.Coin a_coin = 18; string an_address = 19 [(cosmos_proto.scalar) = "cosmos.AddressString"]; - cosmos.base.query.v1beta1.PageRequest page = 20; - repeated bool bools = 21; - repeated uint32 uints = 22; - repeated string strings = 23; - repeated Enum enums = 24; - repeated google.protobuf.Duration durations = 25; - repeated AMessage some_messages = 26; + cosmos.base.query.v1beta1.PageRequest page = 20; + repeated bool bools = 21; + repeated uint32 uints = 22; + repeated string strings = 23; + repeated Enum enums = 24; + repeated google.protobuf.Duration durations = 25; + repeated AMessage some_messages = 26; + + int32 positional1 = 27; + string positional2 = 28; + repeated cosmos.base.v1beta1.Coin positional3_varargs = 29; + + string deprecated_field = 30; + string shorthand_deprecated_field = 31; + bool hidden_bool = 32; } enum Enum { ENUM_UNSPECIFIED = 0; - ENUM_ONE = 1; - ENUM_TWO = 2; - ENUM_FIVE = 5; - ENUM_NEG_THREE = -3; + ENUM_ONE = 1; + ENUM_TWO = 2; + ENUM_FIVE = 5; + ENUM_NEG_THREE = -3; } message AMessage { diff --git a/client/v2/internal/testpb/query.pulsar.go b/client/v2/internal/testpb/query.pulsar.go index 16e9e8ffa8..e8743333c3 100644 --- a/client/v2/internal/testpb/query.pulsar.go +++ b/client/v2/internal/testpb/query.pulsar.go @@ -303,28 +303,85 @@ func (x *_EchoRequest_26_list) IsValid() bool { return x.list != nil } +var _ protoreflect.List = (*_EchoRequest_29_list)(nil) + +type _EchoRequest_29_list struct { + list *[]*v1beta1.Coin +} + +func (x *_EchoRequest_29_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_29_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_EchoRequest_29_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_29_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_29_list) AppendMutable() protoreflect.Value { + v := new(v1beta1.Coin) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_29_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_29_list) NewElement() protoreflect.Value { + v := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_29_list) IsValid() bool { + return x.list != nil +} + var ( - md_EchoRequest protoreflect.MessageDescriptor - fd_EchoRequest_u32 protoreflect.FieldDescriptor - fd_EchoRequest_u64 protoreflect.FieldDescriptor - fd_EchoRequest_str protoreflect.FieldDescriptor - fd_EchoRequest_bz protoreflect.FieldDescriptor - fd_EchoRequest_timestamp protoreflect.FieldDescriptor - fd_EchoRequest_duration protoreflect.FieldDescriptor - fd_EchoRequest_i32 protoreflect.FieldDescriptor - fd_EchoRequest_i64 protoreflect.FieldDescriptor - fd_EchoRequest_a_bool protoreflect.FieldDescriptor - fd_EchoRequest_an_enum protoreflect.FieldDescriptor - fd_EchoRequest_a_message protoreflect.FieldDescriptor - fd_EchoRequest_a_coin protoreflect.FieldDescriptor - fd_EchoRequest_an_address protoreflect.FieldDescriptor - fd_EchoRequest_page protoreflect.FieldDescriptor - fd_EchoRequest_bools protoreflect.FieldDescriptor - fd_EchoRequest_uints protoreflect.FieldDescriptor - fd_EchoRequest_strings protoreflect.FieldDescriptor - fd_EchoRequest_enums protoreflect.FieldDescriptor - fd_EchoRequest_durations protoreflect.FieldDescriptor - fd_EchoRequest_some_messages protoreflect.FieldDescriptor + md_EchoRequest protoreflect.MessageDescriptor + fd_EchoRequest_u32 protoreflect.FieldDescriptor + fd_EchoRequest_u64 protoreflect.FieldDescriptor + fd_EchoRequest_str protoreflect.FieldDescriptor + fd_EchoRequest_bz protoreflect.FieldDescriptor + fd_EchoRequest_timestamp protoreflect.FieldDescriptor + fd_EchoRequest_duration protoreflect.FieldDescriptor + fd_EchoRequest_i32 protoreflect.FieldDescriptor + fd_EchoRequest_i64 protoreflect.FieldDescriptor + fd_EchoRequest_a_bool protoreflect.FieldDescriptor + fd_EchoRequest_an_enum protoreflect.FieldDescriptor + fd_EchoRequest_a_message protoreflect.FieldDescriptor + fd_EchoRequest_a_coin protoreflect.FieldDescriptor + fd_EchoRequest_an_address protoreflect.FieldDescriptor + fd_EchoRequest_page protoreflect.FieldDescriptor + fd_EchoRequest_bools protoreflect.FieldDescriptor + fd_EchoRequest_uints protoreflect.FieldDescriptor + fd_EchoRequest_strings protoreflect.FieldDescriptor + fd_EchoRequest_enums protoreflect.FieldDescriptor + fd_EchoRequest_durations protoreflect.FieldDescriptor + fd_EchoRequest_some_messages protoreflect.FieldDescriptor + fd_EchoRequest_positional1 protoreflect.FieldDescriptor + fd_EchoRequest_positional2 protoreflect.FieldDescriptor + fd_EchoRequest_positional3_varargs protoreflect.FieldDescriptor + fd_EchoRequest_deprecated_field protoreflect.FieldDescriptor + fd_EchoRequest_shorthand_deprecated_field protoreflect.FieldDescriptor + fd_EchoRequest_hidden_bool protoreflect.FieldDescriptor ) func init() { @@ -350,6 +407,12 @@ func init() { fd_EchoRequest_enums = md_EchoRequest.Fields().ByName("enums") fd_EchoRequest_durations = md_EchoRequest.Fields().ByName("durations") fd_EchoRequest_some_messages = md_EchoRequest.Fields().ByName("some_messages") + fd_EchoRequest_positional1 = md_EchoRequest.Fields().ByName("positional1") + fd_EchoRequest_positional2 = md_EchoRequest.Fields().ByName("positional2") + fd_EchoRequest_positional3_varargs = md_EchoRequest.Fields().ByName("positional3_varargs") + fd_EchoRequest_deprecated_field = md_EchoRequest.Fields().ByName("deprecated_field") + fd_EchoRequest_shorthand_deprecated_field = md_EchoRequest.Fields().ByName("shorthand_deprecated_field") + fd_EchoRequest_hidden_bool = md_EchoRequest.Fields().ByName("hidden_bool") } var _ protoreflect.Message = (*fastReflection_EchoRequest)(nil) @@ -537,6 +600,42 @@ func (x *fastReflection_EchoRequest) Range(f func(protoreflect.FieldDescriptor, return } } + if x.Positional1 != int32(0) { + value := protoreflect.ValueOfInt32(x.Positional1) + if !f(fd_EchoRequest_positional1, value) { + return + } + } + if x.Positional2 != "" { + value := protoreflect.ValueOfString(x.Positional2) + if !f(fd_EchoRequest_positional2, value) { + return + } + } + if len(x.Positional3Varargs) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_29_list{list: &x.Positional3Varargs}) + if !f(fd_EchoRequest_positional3_varargs, value) { + return + } + } + if x.DeprecatedField != "" { + value := protoreflect.ValueOfString(x.DeprecatedField) + if !f(fd_EchoRequest_deprecated_field, value) { + return + } + } + if x.ShorthandDeprecatedField != "" { + value := protoreflect.ValueOfString(x.ShorthandDeprecatedField) + if !f(fd_EchoRequest_shorthand_deprecated_field, value) { + return + } + } + if x.HiddenBool != false { + value := protoreflect.ValueOfBool(x.HiddenBool) + if !f(fd_EchoRequest_hidden_bool, value) { + return + } + } } // Has reports whether a field is populated. @@ -592,6 +691,18 @@ func (x *fastReflection_EchoRequest) Has(fd protoreflect.FieldDescriptor) bool { return len(x.Durations) != 0 case "testpb.EchoRequest.some_messages": return len(x.SomeMessages) != 0 + case "testpb.EchoRequest.positional1": + return x.Positional1 != int32(0) + case "testpb.EchoRequest.positional2": + return x.Positional2 != "" + case "testpb.EchoRequest.positional3_varargs": + return len(x.Positional3Varargs) != 0 + case "testpb.EchoRequest.deprecated_field": + return x.DeprecatedField != "" + case "testpb.EchoRequest.shorthand_deprecated_field": + return x.ShorthandDeprecatedField != "" + case "testpb.EchoRequest.hidden_bool": + return x.HiddenBool != false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -648,6 +759,18 @@ func (x *fastReflection_EchoRequest) Clear(fd protoreflect.FieldDescriptor) { x.Durations = nil case "testpb.EchoRequest.some_messages": x.SomeMessages = nil + case "testpb.EchoRequest.positional1": + x.Positional1 = int32(0) + case "testpb.EchoRequest.positional2": + x.Positional2 = "" + case "testpb.EchoRequest.positional3_varargs": + x.Positional3Varargs = nil + case "testpb.EchoRequest.deprecated_field": + x.DeprecatedField = "" + case "testpb.EchoRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = "" + case "testpb.EchoRequest.hidden_bool": + x.HiddenBool = false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -742,6 +865,27 @@ func (x *fastReflection_EchoRequest) Get(descriptor protoreflect.FieldDescriptor } listValue := &_EchoRequest_26_list{list: &x.SomeMessages} return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.positional1": + value := x.Positional1 + return protoreflect.ValueOfInt32(value) + case "testpb.EchoRequest.positional2": + value := x.Positional2 + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.positional3_varargs": + if len(x.Positional3Varargs) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_29_list{}) + } + listValue := &_EchoRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.deprecated_field": + value := x.DeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.shorthand_deprecated_field": + value := x.ShorthandDeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.hidden_bool": + value := x.HiddenBool + return protoreflect.ValueOfBool(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -814,6 +958,20 @@ func (x *fastReflection_EchoRequest) Set(fd protoreflect.FieldDescriptor, value lv := value.List() clv := lv.(*_EchoRequest_26_list) x.SomeMessages = *clv.list + case "testpb.EchoRequest.positional1": + x.Positional1 = int32(value.Int()) + case "testpb.EchoRequest.positional2": + x.Positional2 = value.Interface().(string) + case "testpb.EchoRequest.positional3_varargs": + lv := value.List() + clv := lv.(*_EchoRequest_29_list) + x.Positional3Varargs = *clv.list + case "testpb.EchoRequest.deprecated_field": + x.DeprecatedField = value.Interface().(string) + case "testpb.EchoRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = value.Interface().(string) + case "testpb.EchoRequest.hidden_bool": + x.HiddenBool = value.Bool() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -895,6 +1053,12 @@ func (x *fastReflection_EchoRequest) Mutable(fd protoreflect.FieldDescriptor) pr } value := &_EchoRequest_26_list{list: &x.SomeMessages} return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.positional3_varargs": + if x.Positional3Varargs == nil { + x.Positional3Varargs = []*v1beta1.Coin{} + } + value := &_EchoRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(value) case "testpb.EchoRequest.u32": panic(fmt.Errorf("field u32 of message testpb.EchoRequest is not mutable")) case "testpb.EchoRequest.u64": @@ -913,6 +1077,16 @@ func (x *fastReflection_EchoRequest) Mutable(fd protoreflect.FieldDescriptor) pr panic(fmt.Errorf("field an_enum of message testpb.EchoRequest is not mutable")) case "testpb.EchoRequest.an_address": panic(fmt.Errorf("field an_address of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.positional1": + panic(fmt.Errorf("field positional1 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.positional2": + panic(fmt.Errorf("field positional2 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.deprecated_field": + panic(fmt.Errorf("field deprecated_field of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.shorthand_deprecated_field": + panic(fmt.Errorf("field shorthand_deprecated_field of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.hidden_bool": + panic(fmt.Errorf("field hidden_bool of message testpb.EchoRequest is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -977,6 +1151,19 @@ func (x *fastReflection_EchoRequest) NewField(fd protoreflect.FieldDescriptor) p case "testpb.EchoRequest.some_messages": list := []*AMessage{} return protoreflect.ValueOfList(&_EchoRequest_26_list{list: &list}) + case "testpb.EchoRequest.positional1": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.EchoRequest.positional2": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.positional3_varargs": + list := []*v1beta1.Coin{} + return protoreflect.ValueOfList(&_EchoRequest_29_list{list: &list}) + case "testpb.EchoRequest.deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.shorthand_deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.hidden_bool": + return protoreflect.ValueOfBool(false) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) @@ -1131,6 +1318,30 @@ func (x *fastReflection_EchoRequest) ProtoMethods() *protoiface.Methods { n += 2 + l + runtime.Sov(uint64(l)) } } + if x.Positional1 != 0 { + n += 2 + runtime.Sov(uint64(x.Positional1)) + } + l = len(x.Positional2) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Positional3Varargs) > 0 { + for _, e := range x.Positional3Varargs { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + l = len(x.DeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.ShorthandDeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.HiddenBool { + n += 3 + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1160,6 +1371,70 @@ func (x *fastReflection_EchoRequest) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.HiddenBool { + i-- + if x.HiddenBool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x80 + } + if len(x.ShorthandDeprecatedField) > 0 { + i -= len(x.ShorthandDeprecatedField) + copy(dAtA[i:], x.ShorthandDeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ShorthandDeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xfa + } + if len(x.DeprecatedField) > 0 { + i -= len(x.DeprecatedField) + copy(dAtA[i:], x.DeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xf2 + } + if len(x.Positional3Varargs) > 0 { + for iNdEx := len(x.Positional3Varargs) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Positional3Varargs[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xea + } + } + if len(x.Positional2) > 0 { + i -= len(x.Positional2) + copy(dAtA[i:], x.Positional2) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Positional2))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xe2 + } + if x.Positional1 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Positional1)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd8 + } if len(x.SomeMessages) > 0 { for iNdEx := len(x.SomeMessages) - 1; iNdEx >= 0; iNdEx-- { encoded, err := options.Marshal(x.SomeMessages[iNdEx]) @@ -2160,6 +2435,175 @@ func (x *fastReflection_EchoRequest) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex + case 27: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional1", wireType) + } + x.Positional1 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Positional1 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 28: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional2", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional2 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 29: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional3Varargs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional3Varargs = append(x.Positional3Varargs, &v1beta1.Coin{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Positional3Varargs[len(x.Positional3Varargs)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 30: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 31: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ShorthandDeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.ShorthandDeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 32: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field HiddenBool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.HiddenBool = bool(v != 0) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -3172,26 +3616,32 @@ type EchoRequest struct { unknownFields protoimpl.UnknownFields // u32 is an uint32 - U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` - U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` - Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` - Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` - Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` - I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` - I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` - ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` - AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` - AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` - ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` - AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` - Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` - Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` - Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` - Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` - Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` - Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` - SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` + U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` + U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` + Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` + Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` + Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` + I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` + I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` + ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` + AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` + AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` + ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` + AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` + Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` + Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` + Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` + Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` + Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` + Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` + SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` + Positional1 int32 `protobuf:"varint,27,opt,name=positional1,proto3" json:"positional1,omitempty"` + Positional2 string `protobuf:"bytes,28,opt,name=positional2,proto3" json:"positional2,omitempty"` + Positional3Varargs []*v1beta1.Coin `protobuf:"bytes,29,rep,name=positional3_varargs,json=positional3Varargs,proto3" json:"positional3_varargs,omitempty"` + DeprecatedField string `protobuf:"bytes,30,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` + ShorthandDeprecatedField string `protobuf:"bytes,31,opt,name=shorthand_deprecated_field,json=shorthandDeprecatedField,proto3" json:"shorthand_deprecated_field,omitempty"` + HiddenBool bool `protobuf:"varint,32,opt,name=hidden_bool,json=hiddenBool,proto3" json:"hidden_bool,omitempty"` } func (x *EchoRequest) Reset() { @@ -3354,6 +3804,48 @@ func (x *EchoRequest) GetSomeMessages() []*AMessage { return nil } +func (x *EchoRequest) GetPositional1() int32 { + if x != nil { + return x.Positional1 + } + return 0 +} + +func (x *EchoRequest) GetPositional2() string { + if x != nil { + return x.Positional2 + } + return "" +} + +func (x *EchoRequest) GetPositional3Varargs() []*v1beta1.Coin { + if x != nil { + return x.Positional3Varargs + } + return nil +} + +func (x *EchoRequest) GetDeprecatedField() string { + if x != nil { + return x.DeprecatedField + } + return "" +} + +func (x *EchoRequest) GetShorthandDeprecatedField() string { + if x != nil { + return x.ShorthandDeprecatedField + } + return "" +} + +func (x *EchoRequest) GetHiddenBool() bool { + if x != nil { + return x.HiddenBool + } + return false +} + type AMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -3447,7 +3939,7 @@ var file_testpb_query_proto_rawDesc = []byte{ 0x74, 0x61, 0x31, 0x2f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd6, 0x05, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xf0, 0x07, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, @@ -3492,34 +3984,51 @@ var file_testpb_query_proto_rawDesc = []byte{ 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x35, 0x0a, 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, - 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, 0x2e, 0x0a, - 0x08, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, - 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x7a, 0x22, 0x3d, 0x0a, - 0x0c, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, - 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, - 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2a, 0x64, 0x0a, 0x04, - 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, - 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, - 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, - 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, - 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, - 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x01, 0x32, 0x3a, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x31, 0x0a, 0x04, 0x45, - 0x63, 0x68, 0x6f, 0x12, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, - 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x88, - 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0a, 0x51, - 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, - 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, - 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, - 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, - 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x20, 0x0a, + 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x18, 0x1b, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x12, + 0x20, 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x32, 0x18, 0x1c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, + 0x32, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, + 0x5f, 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x12, 0x70, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, 0x56, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x29, 0x0a, + 0x10, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, + 0x64, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, + 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x3c, 0x0a, 0x1a, 0x73, 0x68, 0x6f, 0x72, + 0x74, 0x68, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x73, 0x68, + 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, + 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, + 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x20, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x69, 0x64, + 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x6f, 0x6c, 0x22, 0x2e, 0x0a, 0x08, 0x41, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x62, 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x7a, 0x22, 0x3d, 0x0a, 0x0c, 0x45, 0x63, 0x68, 0x6f, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2a, 0x64, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, + 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, + 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, + 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, + 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, + 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x32, 0x3a, 0x0a, 0x05, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x31, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x13, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x88, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, + 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, + 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, + 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, + 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -3556,14 +4065,15 @@ var file_testpb_query_proto_depIdxs = []int32{ 0, // 6: testpb.EchoRequest.enums:type_name -> testpb.Enum 5, // 7: testpb.EchoRequest.durations:type_name -> google.protobuf.Duration 2, // 8: testpb.EchoRequest.some_messages:type_name -> testpb.AMessage - 1, // 9: testpb.EchoResponse.request:type_name -> testpb.EchoRequest - 1, // 10: testpb.Query.Echo:input_type -> testpb.EchoRequest - 3, // 11: testpb.Query.Echo:output_type -> testpb.EchoResponse - 11, // [11:12] is the sub-list for method output_type - 10, // [10:11] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name + 6, // 9: testpb.EchoRequest.positional3_varargs:type_name -> cosmos.base.v1beta1.Coin + 1, // 10: testpb.EchoResponse.request:type_name -> testpb.EchoRequest + 1, // 11: testpb.Query.Echo:input_type -> testpb.EchoRequest + 3, // 12: testpb.Query.Echo:output_type -> testpb.EchoResponse + 12, // [12:13] is the sub-list for method output_type + 11, // [11:12] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_testpb_query_proto_init() }