From ba163e0fd064efbc6acbae033aed176735de7736 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jul 2023 17:21:58 +0200 Subject: [PATCH] feat(circuit): autocli query support (#16906) --- x/circuit/autocli.go | 35 ++++++++++ x/circuit/client/cli/query.go | 121 ---------------------------------- x/circuit/go.mod | 5 +- x/circuit/go.sum | 10 +-- x/circuit/module.go | 5 -- 5 files changed, 44 insertions(+), 132 deletions(-) create mode 100644 x/circuit/autocli.go delete mode 100644 x/circuit/client/cli/query.go diff --git a/x/circuit/autocli.go b/x/circuit/autocli.go new file mode 100644 index 000000000000..50254dbc1024 --- /dev/null +++ b/x/circuit/autocli.go @@ -0,0 +1,35 @@ +package circuit + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + circuitv1 "cosmossdk.io/api/cosmos/circuit/v1" +) + +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: circuitv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Account", + Use: "account [address]", + Short: "Query a specific account's permissions", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "Accounts", + Use: "accounts", + Short: "Query all account permissions", + }, + { + RpcMethod: "DisabledList", + Use: "disabled-list", + Short: "Query a list of all disabled message types", + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: circuitv1.Query_ServiceDesc.ServiceName, + }, + } +} diff --git a/x/circuit/client/cli/query.go b/x/circuit/client/cli/query.go deleted file mode 100644 index f54bec090975..000000000000 --- a/x/circuit/client/cli/query.go +++ /dev/null @@ -1,121 +0,0 @@ -package cli - -import ( - "github.com/spf13/cobra" - - "cosmossdk.io/x/circuit/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GetQueryCmd returns the parent command for all circuit CLI query commands. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the circuit module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetDisabeListCmd(), - GetAccountCmd(), - GetAccountsCmd(), - ) - - return cmd -} - -func GetDisabeListCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "disabled-list", - Short: "Query for all disabled message types", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.DisabledList(cmd.Context(), &types.QueryDisabledListRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetAccountCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "account [address]", - Short: "Query for account permissions", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - addr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Account(cmd.Context(), &types.QueryAccountRequest{Address: addr.String()}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetAccountsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "accounts", - Short: "Query for all account permissions", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Accounts(cmd.Context(), &types.QueryAccountsRequest{Pagination: pageReq}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 84e13ec33f35..40ecb99b97f1 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -12,7 +12,7 @@ require ( cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c github.com/cockroachdb/errors v1.10.0 github.com/cometbft/cometbft v0.38.0-rc2 - github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801 + github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff github.com/cosmos/gogoproto v1.4.10 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -23,7 +23,7 @@ require ( ) require ( - cosmossdk.io/log v1.1.0 // indirect + cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect cosmossdk.io/x/tx v0.8.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -82,6 +82,7 @@ require ( github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect + github.com/hashicorp/go-metrics v0.5.1 // indirect github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/x/circuit/go.sum b/x/circuit/go.sum index c34165445092..a59a4e91ae64 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -45,8 +45,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU= cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741 h1:BCRz06fvddw7cKGiEGDiSox3qMsjQ97f92K+PDZDHdc= cosmossdk.io/errors v1.0.0-beta.7.0.20230524212735-6cabb6aa5741/go.mod h1:TB05o6YXkZkzsc+6bZFAV5kZRBtoCU9tUkbeMIqEg0w= -cosmossdk.io/log v1.1.0 h1:v0ogPHYeTzPcBTcPR1A3j1hkei4pZama8kz8LKlCMv0= -cosmossdk.io/log v1.1.0/go.mod h1:6zjroETlcDs+mm62gd8Ig7mZ+N+fVOZS91V17H+M4N4= +cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca h1:msenprh2BLLRwNT7zN56TbBHOGk/7ARQckXHxXyvjoQ= +cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca/go.mod h1:PkIAKXZvaxrTRc++z53XMRvFk8AcGGWYHcMIPzVYX9c= cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg= cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k= cosmossdk.io/store v0.1.0-alpha.1.0.20230606190835-3e18f4088b2c h1:A+FMPW9GtfcPBDQNtFeDFN27h1SAP6OVjnGgPLlYXmI= @@ -170,8 +170,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0 github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801 h1:Qg0EgcEYtN0RWmxaFWTTCeMDfnbHB6UEzHucafy14i8= -github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230614103911-b3da8bb4e801/go.mod h1:VwFzgpv4z/Mrx+0sQpWwURCHx4h/iAalMdKIe3VEyBw= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff h1:jqNK08KgB3ExmUWsG8VNo+3QSODQnFefEiLNTKbcx2A= +github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230710133622-f3e4697195ff/go.mod h1:dmZ0kV7SplzqHiYR9aV/iIpIGVoUF8r0NfiigmXxKeM= 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= @@ -421,6 +421,8 @@ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U= +github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= diff --git a/x/circuit/module.go b/x/circuit/module.go index 406bd2930056..0937ff71e854 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -79,11 +79,6 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.NewTxCmd() } -// GetQueryCmd returns no root query command for the circuit module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - // RegisterInterfaces registers interfaces and implementations of the circuit module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry)