From 32123dac68812bd238f7ce2b810fd292d9efdd6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDongLieu=E2=80=9D?= Date: Mon, 2 Dec 2024 16:13:33 +0700 Subject: [PATCH] autocli for querry accounts --- x/accounts/autocli.go | 37 ++++++++++++++++++++++++++++++++++ x/accounts/cli/cli.go | 47 ------------------------------------------- x/accounts/module.go | 2 +- 3 files changed, 38 insertions(+), 48 deletions(-) create mode 100644 x/accounts/autocli.go diff --git a/x/accounts/autocli.go b/x/accounts/autocli.go new file mode 100644 index 000000000000..02d92485c445 --- /dev/null +++ b/x/accounts/autocli.go @@ -0,0 +1,37 @@ +package accounts + +import ( + accountsv1 "cosmossdk.io/api/cosmos/accounts/v1" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "fmt" + + "github.com/cosmos/cosmos-sdk/version" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: accountsv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "AccountQuery", + Use: "query ", + Short: "Query account state", + Example: fmt.Sprintf(`%s q accounts query cosmos1uds6tz96dxfllz7tz3s3tm8tlg6x95g0mc2987sx6psjz98qlpss89sheu cosmos.accounts.defaults.multisig.v1.QueryProposal '{"proposal_id":1}`, version.AppName), + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "target"}, + {ProtoField: "query_request_type_url"}, + {ProtoField: "json_message"}, + }, + }, + }, + EnhanceCustomCommand: true, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: accountsv1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + EnhanceCustomCommand: true, + }, + } +} diff --git a/x/accounts/cli/cli.go b/x/accounts/cli/cli.go index 97db60c8c999..4f58baf9cb4e 100644 --- a/x/accounts/cli/cli.go +++ b/x/accounts/cli/cli.go @@ -28,17 +28,6 @@ func TxCmd(name string) *cobra.Command { return cmd } -func QueryCmd(name string) *cobra.Command { - cmd := &cobra.Command{ - Use: name, - Short: "Query command for the " + name + " module", - RunE: client.ValidateCmd, - DisableFlagParsing: true, - } - cmd.AddCommand(GetQueryAccountCmd()) - return cmd -} - func GetTxInitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "init ", @@ -130,42 +119,6 @@ func GetExecuteCmd() *cobra.Command { return cmd } -func GetQueryAccountCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "query ", - Short: "Query account state", - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - // schema, err := getSchemaForAccount(clientCtx, args[0]) - // if err != nil { - // return err - // } - // msgBytes, err := handlerMsgBytes(schema.QueryHandlers, args[1], args[2]) - // if err != nil { - // return err - // } - queryClient := v1.NewQueryClient(clientCtx) - res, err := queryClient.AccountQuery(cmd.Context(), &v1.AccountQueryRequest{ - Target: args[0], - // Request: msgBytes, - QueryRequestTypeUrl: args[1], - JsonMessage: args[2], - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - func getSchemaForAccount(clientCtx client.Context, addr string) (*v1.SchemaResponse, error) { queryClient := v1.NewQueryClient(clientCtx) accType, err := queryClient.AccountType(clientCtx.CmdContext, &v1.AccountTypeRequest{ diff --git a/x/accounts/module.go b/x/accounts/module.go index daadebfe91ce..5f36062b4fde 100644 --- a/x/accounts/module.go +++ b/x/accounts/module.go @@ -121,7 +121,7 @@ func (AppModule) GetTxCmd() *cobra.Command { } func (AppModule) GetQueryCmd() *cobra.Command { - return cli.QueryCmd(ModuleName) + return nil } func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }