github.com/Finschia/finschia-sdk@v0.49.1/x/fswap/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 "github.com/Finschia/finschia-sdk/client" 9 "github.com/Finschia/finschia-sdk/client/flags" 10 "github.com/Finschia/finschia-sdk/x/fswap/types" 11 ) 12 13 // GetQueryCmd returns the cli query commands for this module 14 func GetQueryCmd(queryRoute string) *cobra.Command { 15 // Group fswap queries under a subcommand 16 cmd := &cobra.Command{ 17 Use: queryRoute, 18 Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), 19 DisableFlagParsing: true, 20 SuggestionsMinimumDistance: 2, 21 RunE: client.ValidateCmd, 22 } 23 24 cmd.AddCommand( 25 CmdQuerySwapped(), 26 CmdQueryTotalSwappableAmount(), 27 CmdQuerySwap(), 28 CmdQuerySwaps(), 29 ) 30 return cmd 31 } 32 33 func CmdQuerySwapped() *cobra.Command { 34 cmd := &cobra.Command{ 35 Use: "swapped [from_denom] [to_denom]", 36 Short: "shows the current swap status, including both old and new coin amount", 37 Args: cobra.ExactArgs(2), 38 RunE: func(cmd *cobra.Command, args []string) error { 39 clientCtx, err := client.GetClientQueryContext(cmd) 40 if err != nil { 41 return err 42 } 43 queryClient := types.NewQueryClient(clientCtx) 44 req := &types.QuerySwappedRequest{ 45 FromDenom: args[0], 46 ToDenom: args[1], 47 } 48 res, err := queryClient.Swapped(cmd.Context(), req) 49 if err != nil { 50 return err 51 } 52 53 return clientCtx.PrintProto(res) 54 }, 55 } 56 57 flags.AddQueryFlagsToCmd(cmd) 58 return cmd 59 } 60 61 func CmdQueryTotalSwappableAmount() *cobra.Command { 62 cmd := &cobra.Command{ 63 Use: "total-swappable-amount [from_denom] [to_denom]", 64 Short: "shows the current total amount of new coin that're swappable", 65 Args: cobra.ExactArgs(2), 66 RunE: func(cmd *cobra.Command, args []string) error { 67 clientCtx, err := client.GetClientQueryContext(cmd) 68 if err != nil { 69 return err 70 } 71 queryClient := types.NewQueryClient(clientCtx) 72 73 req := &types.QueryTotalSwappableToCoinAmountRequest{ 74 FromDenom: args[0], 75 ToDenom: args[1], 76 } 77 res, err := queryClient.TotalSwappableToCoinAmount(cmd.Context(), req) 78 if err != nil { 79 return err 80 } 81 82 return clientCtx.PrintProto(res) 83 }, 84 } 85 86 flags.AddQueryFlagsToCmd(cmd) 87 return cmd 88 } 89 90 func CmdQuerySwap() *cobra.Command { 91 cmd := &cobra.Command{ 92 Use: "swap [from_denom] [to_denom]", 93 Short: "shows a swap", 94 Args: cobra.ExactArgs(2), 95 RunE: func(cmd *cobra.Command, args []string) error { 96 clientCtx, err := client.GetClientQueryContext(cmd) 97 if err != nil { 98 return err 99 } 100 queryClient := types.NewQueryClient(clientCtx) 101 102 req := &types.QuerySwapRequest{ 103 FromDenom: args[0], 104 ToDenom: args[1], 105 } 106 107 res, err := queryClient.Swap(cmd.Context(), req) 108 if err != nil { 109 return err 110 } 111 112 return clientCtx.PrintProto(res) 113 }, 114 } 115 116 flags.AddQueryFlagsToCmd(cmd) 117 return cmd 118 } 119 120 func CmdQuerySwaps() *cobra.Command { 121 cmd := &cobra.Command{ 122 Use: "swaps", 123 Short: "shows the all the swaps", 124 Args: cobra.NoArgs, 125 RunE: func(cmd *cobra.Command, args []string) error { 126 clientCtx, err := client.GetClientQueryContext(cmd) 127 if err != nil { 128 return err 129 } 130 queryClient := types.NewQueryClient(clientCtx) 131 132 pageReq, err := client.ReadPageRequest(cmd.Flags()) 133 if err != nil { 134 return err 135 } 136 137 req := &types.QuerySwapsRequest{ 138 Pagination: pageReq, 139 } 140 res, err := queryClient.Swaps(cmd.Context(), req) 141 if err != nil { 142 return err 143 } 144 145 return clientCtx.PrintProto(res) 146 }, 147 } 148 149 flags.AddQueryFlagsToCmd(cmd) 150 return cmd 151 }