2020-06-12 19:45:07 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2022-01-08 00:39:27 +00:00
|
|
|
"context"
|
2020-06-12 19:45:07 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-06-12 19:45:07 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/kavadist/types"
|
2020-06-12 19:45:07 +00:00
|
|
|
)
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
|
|
|
func GetQueryCmd() *cobra.Command {
|
|
|
|
// Group kavadist queries under a subcommand
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
|
|
|
|
DisableFlagParsing: true,
|
|
|
|
SuggestionsMinimumDistance: 2,
|
|
|
|
RunE: client.ValidateCmd,
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
cmd.AddCommand(
|
|
|
|
queryParamsCmd(),
|
|
|
|
queryBalanceCmd(),
|
|
|
|
)
|
2020-06-12 19:45:07 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
return cmd
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func queryParamsCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
2020-06-12 19:45:07 +00:00
|
|
|
Use: "params",
|
|
|
|
Short: "get the kavadist module parameters",
|
|
|
|
Long: "Get the current global kavadist module parameters.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
2020-06-12 19:45:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
queryClient := types.NewQueryClient(cliCtx)
|
|
|
|
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return cliCtx.PrintProto(&res.Params)
|
2020-06-12 19:45:07 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
flags.AddQueryFlagsToCmd(cmd)
|
|
|
|
return cmd
|
2020-06-12 19:45:07 +00:00
|
|
|
}
|
2020-06-17 13:04:16 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func queryBalanceCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
2020-06-17 13:04:16 +00:00
|
|
|
Use: "balance",
|
|
|
|
Short: "get the kavadist module balance",
|
|
|
|
Long: "Get the current kavadist module account balance.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-01-08 00:39:27 +00:00
|
|
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
2020-06-17 13:04:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
queryClient := types.NewQueryClient(cliCtx)
|
|
|
|
res, err := queryClient.Balance(context.Background(), &types.QueryBalanceRequest{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-06-17 13:04:16 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return cliCtx.PrintProto(res)
|
2020-06-17 13:04:16 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
flags.AddQueryFlagsToCmd(cmd)
|
|
|
|
return cmd
|
2020-06-17 13:04:16 +00:00
|
|
|
}
|