Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): add auto cli for node service (backport #21074) #21317

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Features

* (tools/confix) [#21052](https://github.com/cosmos/cosmos-sdk/pull/21052) Add a migration to v2 config.
* (client) [#21074](https://github.com/cosmos/cosmos-sdk/pull/21074) Add auto cli for node service
* (tests) [#20013](https://github.com/cosmos/cosmos-sdk/pull/20013) Introduce system tests to run multi node local testnet in CI
* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime.
* (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`.
Expand Down Expand Up @@ -121,10 +121,11 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (testutil/integration) [#21006](https://github.com/cosmos/cosmos-sdk/pull/21006) Fix `NewIntegrationApp` method not writing default genesis to state

### API Breaking Changes

* (sims) [#21039](https://github.com/cosmos/cosmos-sdk/pull/21039): Remove Baseapp from sims by a new interface `simtypes.AppEntrypoint`
* (client) [#20976](https://github.com/cosmos/cosmos-sdk/pull/20976) Simplified command initialization by removing unnecessary parameters such as `txConfig` and `addressCodec`.
* Remove parameter `txConfig` from `genutilcli.Commands`,`genutilcli.CommandsWithCustomMigrationMap`,`genutilcli.GenTxCmd`.
* Remove parameter `addressCodec` from `genutilcli.GenTxCmd`,`genutilcli.AddGenesisAccountCmd`,`stakingcli.BuildCreateValidatorMsg`.
* Remove parameter `txConfig` from `genutilcli.Commands`,`genutilcli.CommandsWithCustomMigrationMap`,`genutilcli.GenTxCmd`.
* Remove parameter `addressCodec` from `genutilcli.GenTxCmd`,`genutilcli.AddGenesisAccountCmd`,`stakingcli.BuildCreateValidatorMsg`.
* (x/genutil) [#20740](https://github.com/cosmos/cosmos-sdk/pull/20740) Update `genutilcli.Commands` and `genutilcli.CommandsWithCustomMigrationMap` to take the genesis module and abstract the module manager.
* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Deprecated `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetCometConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config`
* (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`.
Expand Down
43 changes: 43 additions & 0 deletions client/grpc/node/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package node

import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
nodev1beta1 "cosmossdk.io/api/cosmos/base/node/v1beta1"
)

var ServiceAutoCLIDescriptor = &autocliv1.ServiceCommandDescriptor{
Service: nodev1beta1.Service_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Config",
Use: "config",
Short: "Query the current node config",
},
{
RpcMethod: "Status",
Use: "status",
Short: "Query the current node status",
},
},
}

// NewNodeCommands is a fake `appmodule.Module` to be considered as a module
// and be added in AutoCLI.
func NewNodeCommands() *nodeModule {
return &nodeModule{}
}

type nodeModule struct{}

func (m nodeModule) IsOnePerModuleType() {}
func (m nodeModule) IsAppModule() {}

func (m nodeModule) Name() string {
return "node"
}

func (m nodeModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: ServiceAutoCLIDescriptor,
}
}
4 changes: 4 additions & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
Expand Down Expand Up @@ -122,6 +123,9 @@ func NewRootCmd() *cobra.Command {
autoCliOpts := tempApp.AutoCliOpts()
autoCliOpts.ClientCtx = initClientCtx

nodeCmds := nodeservice.NewNodeCommands()
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down
6 changes: 6 additions & 0 deletions simapp/simd/cmd/root_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"

authv1 "cosmossdk.io/api/cosmos/auth/module/v1"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
stakingv1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/address"
Expand All @@ -18,6 +19,7 @@ import (
"cosmossdk.io/x/auth/tx"
authtxconfig "cosmossdk.io/x/auth/tx/config"
"cosmossdk.io/x/auth/types"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down Expand Up @@ -83,6 +85,10 @@ func NewRootCmd() *cobra.Command {

initRootCmd(rootCmd, moduleManager)

nodeCmds := nodeservice.NewNodeCommands()
autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions)
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down
7 changes: 7 additions & 0 deletions simapp/v2/simdv2/cmd/root_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/address"
"cosmossdk.io/core/legacy"
Expand All @@ -19,6 +20,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
Expand Down Expand Up @@ -81,6 +83,11 @@ func NewRootCmd[T transaction.Tx]() *cobra.Command {
}

initRootCmd[T](rootCmd, clientCtx.TxConfig, moduleManager)

nodeCmds := nodeservice.NewNodeCommands()
autoCliOpts.ModuleOptions = make(map[string]*autocliv1.ModuleOptions)
autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions()

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
Expand Down
Loading