Skip to content

Commit

Permalink
autocli for querry accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Dec 2, 2024
1 parent 2e94816 commit 32123da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
37 changes: 37 additions & 0 deletions x/accounts/autocli.go
Original file line number Diff line number Diff line change
@@ -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 <account-address> <query-request-type-url> <json-message>",
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,
},
}
}
47 changes: 0 additions & 47 deletions x/accounts/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <account-type> <json-message>",
Expand Down Expand Up @@ -130,42 +119,6 @@ func GetExecuteCmd() *cobra.Command {
return cmd
}

func GetQueryAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "query <account-address> <query-request-type-url> <json-message>",
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{
Expand Down
2 changes: 1 addition & 1 deletion x/accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit 32123da

Please sign in to comment.