github.com/KiraCore/sekai@v0.3.43/x/layer2/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "context" 5 6 "github.com/spf13/cobra" 7 8 "github.com/cosmos/cosmos-sdk/client" 9 "github.com/cosmos/cosmos-sdk/client/flags" 10 11 "github.com/KiraCore/sekai/x/layer2/types" 12 ) 13 14 // NewQueryCmd returns a root CLI command handler for all x/layer2 transaction commands. 15 func NewQueryCmd() *cobra.Command { 16 queryCmd := &cobra.Command{ 17 Use: types.RouterKey, 18 Short: "query commands for the layer2 module", 19 } 20 queryCmd.AddCommand( 21 GetCmdQueryExecutionRegistrar(), 22 GetCmdQueryAllDapps(), 23 GetCmdQueryTransferDapp(), 24 GetCmdQueryGlobalTokens(), 25 ) 26 27 return queryCmd 28 } 29 30 func GetCmdQueryExecutionRegistrar() *cobra.Command { 31 cmd := &cobra.Command{ 32 Use: "execution-registrar [dapp-name]", 33 Short: "Queries a execution registrar for a dapp", 34 Args: cobra.MinimumNArgs(1), 35 RunE: func(cmd *cobra.Command, args []string) error { 36 clientCtx := client.GetClientContextFromCmd(cmd) 37 38 queryClient := types.NewQueryClient(clientCtx) 39 res, err := queryClient.ExecutionRegistrar(context.Background(), &types.QueryExecutionRegistrarRequest{ 40 Identifier: args[0], 41 }) 42 if err != nil { 43 return err 44 } 45 46 return clientCtx.PrintProto(res) 47 }, 48 } 49 50 flags.AddQueryFlagsToCmd(cmd) 51 52 return cmd 53 } 54 55 func GetCmdQueryAllDapps() *cobra.Command { 56 cmd := &cobra.Command{ 57 Use: "all-dapps", 58 Short: "Queries all dapps", 59 Args: cobra.MinimumNArgs(0), 60 RunE: func(cmd *cobra.Command, args []string) error { 61 clientCtx := client.GetClientContextFromCmd(cmd) 62 63 queryClient := types.NewQueryClient(clientCtx) 64 res, err := queryClient.AllDapps(context.Background(), &types.QueryAllDappsRequest{}) 65 if err != nil { 66 return err 67 } 68 69 return clientCtx.PrintProto(res) 70 }, 71 } 72 73 flags.AddQueryFlagsToCmd(cmd) 74 75 return cmd 76 } 77 78 func GetCmdQueryTransferDapp() *cobra.Command { 79 cmd := &cobra.Command{ 80 Use: "transfer-dapps", 81 Short: "Queries transfer dapps", 82 Args: cobra.MinimumNArgs(0), 83 RunE: func(cmd *cobra.Command, args []string) error { 84 clientCtx := client.GetClientContextFromCmd(cmd) 85 86 queryClient := types.NewQueryClient(clientCtx) 87 res, err := queryClient.TransferDapps(context.Background(), &types.QueryTransferDappsRequest{}) 88 if err != nil { 89 return err 90 } 91 92 return clientCtx.PrintProto(res) 93 }, 94 } 95 96 flags.AddQueryFlagsToCmd(cmd) 97 98 return cmd 99 } 100 101 func GetCmdQueryGlobalTokens() *cobra.Command { 102 cmd := &cobra.Command{ 103 Use: "global-tokens", 104 Short: "Queries global tokens", 105 Args: cobra.MinimumNArgs(0), 106 RunE: func(cmd *cobra.Command, args []string) error { 107 clientCtx := client.GetClientContextFromCmd(cmd) 108 109 queryClient := types.NewQueryClient(clientCtx) 110 res, err := queryClient.GlobalTokens(context.Background(), &types.QueryGlobalTokensRequest{}) 111 if err != nil { 112 return err 113 } 114 115 return clientCtx.PrintProto(res) 116 }, 117 } 118 119 flags.AddQueryFlagsToCmd(cmd) 120 121 return cmd 122 }