Skip to content

Commit 2a32f42

Browse files
feat(client/v2): implement version filtering using annotation (backport #20083) (#20099)
Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent a2abf1a commit 2a32f42

14 files changed

Lines changed: 983 additions & 472 deletions

File tree

client/v2/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
4242

4343
* (deps) [#19810](https://github.com/cosmos/cosmos-sdk/pull/19810) Upgrade SDK version to due prometheus breaking change.
4444
* (deps) [#19810](https://github.com/cosmos/cosmos-sdk/pull/19810) Bump `cosmossdk.io/store` to v1.1.0.
45+
* [#20083](https://github.com/cosmos/cosmos-sdk/pull/20083) Integrate latest version of cosmos-proto and improve version filtering.
4546
* [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Marshal enum as string in queries.
4647
* [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands.
47-
* Note, the given command must have a `client.Context` in its context.
48+
* Note, the given command must have a `client.Context` in its context.
4849
* [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app.
4950

5051
### Bug Fixes

client/v2/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ err := autoCliOpts.EnhanceRootCommand(rootCmd)
114114
## Signing
115115

116116
`autocli` supports signing transactions with the keyring.
117-
The [`cosmos.msg.v1.signer` protobuf annotation](https://github.com/cosmos/cosmos-sdk/blob/9dd34510e27376005e7e7ff3628eab9dbc8ad6dc/docs/build/building-modules/05-protobuf-annotations.md#L9) defines the signer field of the message.
117+
The [`cosmos.msg.v1.signer` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) defines the signer field of the message.
118118
This field is automatically filled when using the `--from` flag or defining the signer as a positional argument.
119119

120120
:::warning
@@ -194,6 +194,19 @@ https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a
194194

195195
If not set to true, `AutoCLI` will not generate commands for the module if there are already commands registered for the module (when `GetTxCmd()` or `GetTxCmd()` are defined).
196196

197+
### Skip a command
198+
199+
AutoCLI automatically skips unsupported commands when [`cosmos_proto.method_added_in` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) is present.
200+
201+
Additionally, a command can be manually skipped using the `autocliv1.RpcCommandOptions`:
202+
203+
```go
204+
*autocliv1.RpcCommandOptions{
205+
RpcMethod: "Params", // The name of the gRPC service
206+
Skip: true,
207+
}
208+
```
209+
197210
### Use AutoCLI for non module commands
198211

199212
It is possible to use `AutoCLI` for non module commands. The trick is still to implement the `appmodule.Module` interface and append it to the `appOptions.ModuleOptions` map.

client/v2/autocli/common.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip
3232
short = fmt.Sprintf("Execute the %s RPC method", descriptor.Name())
3333
}
3434

35-
long := options.Long
36-
if long == "" {
37-
long = util.DescriptorDocs(descriptor)
38-
}
39-
4035
inputDesc := descriptor.Input()
4136
inputType := util.ResolveMessageType(b.TypeResolver, inputDesc)
4237

@@ -48,7 +43,7 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip
4843
cmd := &cobra.Command{
4944
SilenceUsage: false,
5045
Use: use,
51-
Long: long,
46+
Long: options.Long,
5247
Short: short,
5348
Example: options.Example,
5449
Aliases: options.Alias,

client/v2/autocli/flag/builder.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ func (b *Builder) addFieldFlag(ctx context.Context, flagSet *pflag.FlagSet, fiel
307307
}
308308

309309
usage := opts.Usage
310-
if usage == "" {
311-
usage = util.DescriptorDocs(field)
312-
}
313-
314310
shorthand := opts.Shorthand
315311
defaultValue := opts.DefaultValue
316312

client/v2/autocli/msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc
8383
continue
8484
}
8585

86-
if !util.IsSupportedVersion(util.DescriptorDocs(methodDescriptor)) {
86+
if !util.IsSupportedVersion(methodDescriptor) {
8787
continue
8888
}
8989

client/v2/autocli/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut
8585
continue
8686
}
8787

88-
if !util.IsSupportedVersion(util.DescriptorDocs(methodDescriptor)) {
88+
if !util.IsSupportedVersion(methodDescriptor) {
8989
continue
9090
}
9191

client/v2/internal/buf.lock

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ deps:
44
- remote: buf.build
55
owner: cosmos
66
repository: cosmos-proto
7-
commit: 1935555c206d4afb9e94615dfd0fad31
7+
commit: 04467658e59e44bbb22fe568206e1f70
8+
digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
89
- remote: buf.build
910
owner: cosmos
1011
repository: cosmos-sdk
11-
commit: b7797ff7f3814399b0c5d52e1b8227ed
12+
commit: 05419252bcc241ea8023acf1ed4cadc5
13+
digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5
1214
- remote: buf.build
1315
owner: cosmos
1416
repository: gogo-proto
15-
commit: 6652e3443c3b4504bb3bf82e73a7e409
17+
commit: 88ef6483f90f478fb938c37dde52ece3
18+
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
1619
- remote: buf.build
1720
owner: googleapis
1821
repository: googleapis
19-
commit: 62f35d8aed1149c291d606d958a7ce32
22+
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
23+
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
24+
- remote: buf.build
25+
owner: protocolbuffers
26+
repository: wellknowntypes
27+
commit: 657250e6a39648cbb169d079a60bd9ba
28+
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
29+
- remote: buf.build
30+
owner: tendermint
31+
repository: tendermint
32+
commit: 33ed361a90514289beabf3189e1d7665
33+
digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d

client/v2/internal/testpb/msg.proto

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ import "testpb/query.proto";
1111

1212
service Msg {
1313
// Send a request and returns the request as a response.
14-
rpc Send(MsgRequest) returns (MsgResponse);
14+
rpc Send(MsgRequest) returns (MsgResponse) {
15+
option (cosmos_proto.method_added_in) = "cosmos-sdk v0.50.0";
16+
};
17+
18+
rpc Clawback(MsgClawbackRequest) returns (MsgClawbackResponse) {
19+
option (cosmos_proto.method_added_in) = "cosmos-sdk v0.51.0";
20+
}
1521
}
1622

17-
// MsgRequest is a sample request message
1823
message MsgRequest {
1924
// u32 is an uint32
2025
uint32 u32 = 1;
@@ -51,3 +56,7 @@ message MsgRequest {
5156
message MsgResponse {
5257
MsgRequest request = 1;
5358
}
59+
60+
message MsgClawbackRequest {}
61+
62+
message MsgClawbackResponse {}

0 commit comments

Comments
 (0)