github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/erc20/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags" 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 11 "github.com/fibonacci-chain/fbc/x/erc20/types" 12 "github.com/spf13/cobra" 13 ) 14 15 // GetQueryCmd defines erc20 module queries through the cli 16 func GetQueryCmd(moduleName string, cdc *codec.Codec) *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: types.ModuleName, 19 Short: "Querying commands for the erc20 module", 20 DisableFlagParsing: true, 21 SuggestionsMinimumDistance: 2, 22 RunE: client.ValidateCmd, 23 } 24 cmd.AddCommand(flags.GetCommands( 25 GetCmdQueryParams(moduleName, cdc), 26 GetCmdQueryTokenMapping(moduleName, cdc), 27 GetCmdTemplateContract(moduleName, cdc), 28 )...) 29 return cmd 30 } 31 32 // GetCmdQueryParams implements the query params command. 33 func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command { 34 return &cobra.Command{ 35 Use: "params", 36 Short: "Query all the modifiable parameters of gov proposal", 37 Long: strings.TrimSpace(`Query the all the parameters for the governance process: 38 39 $ fbchaincli query erc20 params 40 `), 41 Args: cobra.NoArgs, 42 RunE: func(_ *cobra.Command, _ []string) error { 43 cliCtx := context.NewCLIContext().WithCodec(cdc) 44 45 route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters) 46 bz, _, err := cliCtx.QueryWithData(route, nil) 47 if err != nil { 48 return err 49 } 50 51 var params types.Params 52 cdc.MustUnmarshalJSON(bz, ¶ms) 53 return cliCtx.PrintOutput(params) 54 }, 55 } 56 } 57 58 func GetCmdQueryTokenMapping(queryRoute string, cdc *codec.Codec) *cobra.Command { 59 return &cobra.Command{ 60 Use: "token-mapping", 61 Short: "Query all token mapping of denom and contract", 62 Long: strings.TrimSpace(`Query all mapping of denom and contract: 63 64 $ fbchaincli query erc20 token-mapping 65 `), 66 Args: cobra.NoArgs, 67 RunE: func(_ *cobra.Command, _ []string) error { 68 cliCtx := context.NewCLIContext().WithCodec(cdc) 69 70 route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryTokenMapping) 71 bz, _, err := cliCtx.QueryWithData(route, nil) 72 if err != nil { 73 return err 74 } 75 76 var mapping []types.QueryTokenMappingResponse 77 cdc.MustUnmarshalJSON(bz, &mapping) 78 return cliCtx.PrintOutput(mapping) 79 }, 80 } 81 } 82 83 func GetCmdTemplateContract(queryRoute string, cdc *codec.Codec) *cobra.Command { 84 return &cobra.Command{ 85 Use: "contract-template", 86 Short: "Query contract-template and note the return value is not available to post as proposal", 87 Long: strings.TrimSpace(`Query all mapping of denom and contract: 88 $ fbchaincli query erc20 contract-template 89 `), 90 Args: cobra.NoArgs, 91 RunE: func(_ *cobra.Command, _ []string) error { 92 cliCtx := context.NewCLIContext().WithCodec(cdc) 93 94 route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryContractTem) 95 bz, _, err := cliCtx.QueryWithData(route, nil) 96 if err != nil { 97 return err 98 } 99 100 return cliCtx.PrintOutput(string(bz)) 101 }, 102 } 103 }