github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/mint/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 10 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/flags" 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 12 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/internal/types" 14 ) 15 16 // GetQueryCmd returns the cli query commands for the minting module. 17 func GetQueryCmd(cdc *codec.Codec) *cobra.Command { 18 mintingQueryCmd := &cobra.Command{ 19 Use: types.ModuleName, 20 Short: "Querying commands for the minting module", 21 DisableFlagParsing: true, 22 SuggestionsMinimumDistance: 2, 23 RunE: client.ValidateCmd, 24 } 25 26 mintingQueryCmd.AddCommand( 27 flags.GetCommands( 28 GetCmdQueryParams(cdc), 29 GetCmdQueryInflation(cdc), 30 GetCmdQueryAnnualProvisions(cdc), 31 GetCmdQueryTreasures(cdc), 32 )..., 33 ) 34 35 return mintingQueryCmd 36 } 37 38 // GetCmdQueryParams implements a command to return the current minting 39 // parameters. 40 func GetCmdQueryParams(cdc *codec.Codec) *cobra.Command { 41 return &cobra.Command{ 42 Use: "params", 43 Short: "Query the current minting parameters", 44 Args: cobra.NoArgs, 45 RunE: func(cmd *cobra.Command, args []string) error { 46 cliCtx := context.NewCLIContext().WithCodec(cdc) 47 48 route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters) 49 res, _, err := cliCtx.QueryWithData(route, nil) 50 if err != nil { 51 return err 52 } 53 54 var params types.Params 55 if err := cdc.UnmarshalJSON(res, ¶ms); err != nil { 56 return err 57 } 58 59 return cliCtx.PrintOutput(params) 60 }, 61 } 62 } 63 64 // GetCmdQueryInflation implements a command to return the current minting 65 // inflation value. 66 func GetCmdQueryInflation(cdc *codec.Codec) *cobra.Command { 67 return &cobra.Command{ 68 Use: "inflation", 69 Short: "Query the current minting inflation value", 70 Args: cobra.NoArgs, 71 RunE: func(cmd *cobra.Command, args []string) error { 72 cliCtx := context.NewCLIContext().WithCodec(cdc) 73 74 route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation) 75 res, _, err := cliCtx.QueryWithData(route, nil) 76 if err != nil { 77 return err 78 } 79 80 var inflation sdk.Dec 81 if err := cdc.UnmarshalJSON(res, &inflation); err != nil { 82 return err 83 } 84 85 return cliCtx.PrintOutput(inflation) 86 }, 87 } 88 } 89 90 // GetCmdQueryAnnualProvisions implements a command to return the current minting 91 // annual provisions value. 92 func GetCmdQueryAnnualProvisions(cdc *codec.Codec) *cobra.Command { 93 return &cobra.Command{ 94 Use: "annual-provisions", 95 Short: "Query the current minting annual provisions value", 96 Args: cobra.NoArgs, 97 RunE: func(cmd *cobra.Command, args []string) error { 98 cliCtx := context.NewCLIContext().WithCodec(cdc) 99 100 route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions) 101 res, _, err := cliCtx.QueryWithData(route, nil) 102 if err != nil { 103 return err 104 } 105 106 var inflation sdk.Dec 107 if err := cdc.UnmarshalJSON(res, &inflation); err != nil { 108 return err 109 } 110 111 return cliCtx.PrintOutput(inflation) 112 }, 113 } 114 } 115 116 // GetCmdQueryTreasures implements a command to return the current minting 117 // treasures. 118 func GetCmdQueryTreasures(cdc *codec.Codec) *cobra.Command { 119 return &cobra.Command{ 120 Use: "treasures", 121 Short: "Query the current treasures", 122 Args: cobra.NoArgs, 123 RunE: func(cmd *cobra.Command, args []string) error { 124 cliCtx := context.NewCLIContext().WithCodec(cdc) 125 126 route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTreasures) 127 res, _, err := cliCtx.QueryWithData(route, nil) 128 if err != nil { 129 return err 130 } 131 132 var treasures []types.Treasure 133 if err := cdc.UnmarshalJSON(res, &treasures); err != nil { 134 return err 135 } 136 137 return cliCtx.PrintOutput(treasures) 138 }, 139 } 140 }