Skip to content

Commit

Permalink
feat(client/v2): implement version filtering using annotation (#20083)
Browse files Browse the repository at this point in the history
(cherry picked from commit b491335)

# Conflicts:
#	client/v2/CHANGELOG.md
#	client/v2/README.md
#	client/v2/go.mod
#	client/v2/go.sum
#	client/v2/internal/offchain/msgSignArbitraryData.pulsar.go
#	tests/starship/tests/go.mod
#	tests/starship/tests/go.sum
  • Loading branch information
julienrbrt authored and mergify[bot] committed Apr 19, 2024
1 parent 49c3ae6 commit 9848550
Show file tree
Hide file tree
Showing 23 changed files with 3,747 additions and 477 deletions.
4 changes: 4 additions & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

<<<<<<< HEAD
* (deps) [#19810](https://github.com/cosmos/cosmos-sdk/pull/19810) Upgrade SDK version to due prometheus breaking change.
* (deps) [#19810](https://github.com/cosmos/cosmos-sdk/pull/19810) Bump `cosmossdk.io/store` to v1.1.0.
=======
* [#20083](https://github.com/cosmos/cosmos-sdk/pull/20083) Integrate latest version of cosmos-proto and improve version filtering.
>>>>>>> b491335e7 (feat(client/v2): implement version filtering using annotation (#20083))
* [#19618](https://github.com/cosmos/cosmos-sdk/pull/19618) Marshal enum as string in queries.
* [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands.
* Note, the given command must have a `client.Context` in its context.
Expand Down
83 changes: 82 additions & 1 deletion client/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ err := autoCliOpts.EnhanceRootCommand(rootCmd)
## Signing

`autocli` supports signing transactions with the keyring.
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.
The [`cosmos.msg.v1.signer` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) defines the signer field of the message.
This field is automatically filled when using the `--from` flag or defining the signer as a positional argument.

:::warning
Expand Down Expand Up @@ -194,6 +194,19 @@ https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a

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).

### Skip a command

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.

Additionally, a command can be manually skipped using the `autocliv1.RpcCommandOptions`:

```go
*autocliv1.RpcCommandOptions{
RpcMethod: "Params", // The name of the gRPC service
Skip: true,
}
```

### Use AutoCLI for non module commands

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.
Expand All @@ -211,3 +224,71 @@ https://github.com/cosmos/cosmos-sdk/blob/client/v2.0.0-beta.1/client/grpc/cmtse
To further enhance your CLI experience with Cosmos SDK-based blockchains, you can use `hubl`. `hubl` is a tool that allows you to query any Cosmos SDK-based blockchain using the new AutoCLI feature of the Cosmos SDK. With `hubl`, you can easily configure a new chain and query modules with just a few simple commands.

For more information on `hubl`, including how to configure a new chain and query a module, see the [Hubl documentation](https://docs.cosmos.network/main/tooling/hubl).
<<<<<<< HEAD
=======

# Off-Chain

Off-chain functionalities allow you to sign and verify files with two commands:

* `sign-file` for signing a file.
* `verify-file` for verifying a previously signed file.

Signing a file will result in a Tx with a `MsgSignArbitraryData` as described in the [Off-chain CIP](https://github.com/cosmos/cips/blob/main/cips/cip-X.md).

## Sign a file

To sign a file `sign-file` command offers some helpful flags:

```text
--encoding string Choose an encoding method for the file content to be added as msg data (no-encoding|base64|hex) (default "no-encoding")
--indent string Choose an indent for the tx (default " ")
--notEmitUnpopulated Don't show unpopulated fields in the tx
--output string Choose an output format for the tx (json|text (default "json")
--output-document string The document will be written to the given file instead of STDOUT
```

The `encoding` flag lets you choose how the contents of the file should be encoded. For example:

* `simd off-chain sign-file alice myFile.json`

* ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "Hello World!\n"
}
```

* `simd off-chain sign-file alice myFile.json --encoding base64`

* ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "SGVsbG8gV29ybGQhCg=="
}
```

* `simd off-chain sign-file alice myFile.json --encoding hex`

* ```json
{
"@type": "/offchain.MsgSignArbitraryData",
"appDomain": "simd",
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
"data": "48656c6c6f20576f726c64210a"
}
```

## Verify a file

To verify a file only the key name used and the previously signed file are needed.

```text
➜ simd off-chain verify-file alice signedFile.json
Verification OK!
```
>>>>>>> b491335e7 (feat(client/v2): implement version filtering using annotation (#20083))
7 changes: 1 addition & 6 deletions client/v2/autocli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip
short = fmt.Sprintf("Execute the %s RPC method", descriptor.Name())
}

long := options.Long
if long == "" {
long = util.DescriptorDocs(descriptor)
}

inputDesc := descriptor.Input()
inputType := util.ResolveMessageType(b.TypeResolver, inputDesc)

Expand All @@ -48,7 +43,7 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip
cmd := &cobra.Command{
SilenceUsage: false,
Use: use,
Long: long,
Long: options.Long,
Short: short,
Example: options.Example,
Aliases: options.Alias,
Expand Down
4 changes: 0 additions & 4 deletions client/v2/autocli/flag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ func (b *Builder) addFieldFlag(ctx context.Context, flagSet *pflag.FlagSet, fiel
}

usage := opts.Usage
if usage == "" {
usage = util.DescriptorDocs(field)
}

shorthand := opts.Shorthand
defaultValue := opts.DefaultValue

Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc
continue
}

if !util.IsSupportedVersion(util.DescriptorDocs(methodDescriptor)) {
if !util.IsSupportedVersion(methodDescriptor) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut
continue
}

if !util.IsSupportedVersion(util.DescriptorDocs(methodDescriptor)) {
if !util.IsSupportedVersion(methodDescriptor) {
continue
}

Expand Down
6 changes: 6 additions & 0 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ require (
cosmossdk.io/math v1.3.0
cosmossdk.io/x/tx v0.13.2
github.com/cockroachdb/errors v1.11.1
<<<<<<< HEAD
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-sdk v0.50.6-0.20240323125140-7397b8672fa8
=======
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.51.0
github.com/manifoldco/promptui v0.9.0 // indirect
>>>>>>> b491335e7 (feat(client/v2): implement version filtering using annotation (#20083))
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
google.golang.org/grpc v1.63.2
Expand Down
5 changes: 5 additions & 0 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk=
github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis=
github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAKs=
github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
<<<<<<< HEAD
github.com/cosmos/cosmos-proto v1.0.0-beta.4 h1:aEL7tU/rLOmxZQ9z4i7mzxcLbSCY48OdY7lIWTLG7oU=
github.com/cosmos/cosmos-proto v1.0.0-beta.4/go.mod h1:oeB+FyVzG3XrQJbJng0EnV8Vljfk9XvTIpGILNU/9Co=
github.com/cosmos/cosmos-sdk v0.50.6-0.20240323125140-7397b8672fa8 h1:FC+jsw+jzBS6hZCZcN2OJe7LLrK4cBvzu+jZQBF13As=
github.com/cosmos/cosmos-sdk v0.50.6-0.20240323125140-7397b8672fa8/go.mod h1:sM3HLOjUE6rwAiuwEOEtPd2DUcXG+uCktW+CdID+ZMM=
=======
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
>>>>>>> b491335e7 (feat(client/v2): implement version filtering using annotation (#20083))
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand Down
22 changes: 18 additions & 4 deletions client/v2/internal/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,30 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
commit: 04467658e59e44bbb22fe568206e1f70
digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: b7797ff7f3814399b0c5d52e1b8227ed
commit: 05419252bcc241ea8023acf1ed4cadc5
digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 6652e3443c3b4504bb3bf82e73a7e409
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 62f35d8aed1149c291d606d958a7ce32
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
- remote: buf.build
owner: protocolbuffers
repository: wellknowntypes
commit: 657250e6a39648cbb169d079a60bd9ba
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
- remote: buf.build
owner: tendermint
repository: tendermint
commit: 33ed361a90514289beabf3189e1d7665
digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d
Loading

0 comments on commit 9848550

Please sign in to comment.