2020-04-24 15:20:34 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2020-04-30 14:23:41 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
2020-04-24 15:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetQueryCmd returns the cli query commands for the incentive module
|
|
|
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
incentiveQueryCmd := &cobra.Command{
|
|
|
|
Use: types.ModuleName,
|
|
|
|
Short: "Querying commands for the incentive module",
|
|
|
|
}
|
|
|
|
|
|
|
|
incentiveQueryCmd.AddCommand(flags.GetCommands(
|
|
|
|
queryParamsCmd(queryRoute, cdc),
|
|
|
|
queryClaimsCmd(queryRoute, cdc),
|
2020-05-28 14:57:22 +00:00
|
|
|
queryRewardPeriodsCmd(queryRoute, cdc),
|
|
|
|
queryClaimPeriodsCmd(queryRoute, cdc),
|
2020-04-24 15:20:34 +00:00
|
|
|
)...)
|
|
|
|
|
|
|
|
return incentiveQueryCmd
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryClaimsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
2020-10-05 19:11:55 +00:00
|
|
|
Use: "claims [owner-addr] [collateral-type]",
|
|
|
|
Short: "get claims by owner and collateral-type",
|
2020-04-24 15:20:34 +00:00
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Get all claims owned by the owner address for the particular collateral type.
|
|
|
|
|
|
|
|
Example:
|
2020-10-05 19:11:55 +00:00
|
|
|
$ %s query %s claims kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw bnb-a`, version.ClientName, types.ModuleName)),
|
2020-04-24 15:20:34 +00:00
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
// Prepare params for querier
|
|
|
|
ownerAddress, err := sdk.AccAddressFromBech32(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
bz, err := cdc.MarshalJSON(types.QueryClaimsParams{
|
2020-08-21 19:42:46 +00:00
|
|
|
Owner: ownerAddress,
|
|
|
|
CollateralType: args[1],
|
2020-04-24 15:20:34 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetClaims)
|
2020-05-28 14:57:22 +00:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, bz)
|
2020-04-24 15:20:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-28 14:57:22 +00:00
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
2020-04-24 15:20:34 +00:00
|
|
|
|
2020-10-05 19:11:55 +00:00
|
|
|
var claims types.AugmentedClaims
|
2020-04-24 15:20:34 +00:00
|
|
|
if err := cdc.UnmarshalJSON(res, &claims); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal claims: %w", err)
|
|
|
|
}
|
|
|
|
return cliCtx.PrintOutput(claims)
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryParamsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "params",
|
|
|
|
Short: "get the incentive module parameters",
|
|
|
|
Long: "Get the current global incentive module parameters.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
// Query
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetParams)
|
2020-05-28 14:57:22 +00:00
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
2020-04-24 15:20:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-28 14:57:22 +00:00
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
2020-04-24 15:20:34 +00:00
|
|
|
|
|
|
|
// Decode and print results
|
|
|
|
var params types.Params
|
|
|
|
if err := cdc.UnmarshalJSON(res, ¶ms); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal params: %w", err)
|
|
|
|
}
|
|
|
|
return cliCtx.PrintOutput(params)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 14:57:22 +00:00
|
|
|
|
|
|
|
func queryRewardPeriodsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "reward-periods",
|
|
|
|
Short: "get active reward periods",
|
|
|
|
Long: "Get the current set of active incentive reward periods.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
// Query
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetRewardPeriods)
|
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
|
|
|
|
// Decode and print results
|
|
|
|
var rewardPeriods types.RewardPeriods
|
|
|
|
if err := cdc.UnmarshalJSON(res, &rewardPeriods); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal reward periods: %w", err)
|
|
|
|
}
|
|
|
|
return cliCtx.PrintOutput(rewardPeriods)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryClaimPeriodsCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "claim-periods",
|
|
|
|
Short: "get active claim periods",
|
|
|
|
Long: "Get the current set of active incentive claim periods.",
|
|
|
|
Args: cobra.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
|
|
|
|
// Query
|
|
|
|
route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetClaimPeriods)
|
|
|
|
res, height, err := cliCtx.QueryWithData(route, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cliCtx = cliCtx.WithHeight(height)
|
|
|
|
|
|
|
|
// Decode and print results
|
|
|
|
var claimPeriods types.ClaimPeriods
|
|
|
|
if err := cdc.UnmarshalJSON(res, &claimPeriods); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal claim periods: %w", err)
|
|
|
|
}
|
|
|
|
return cliCtx.PrintOutput(claimPeriods)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|