0g-chain/x/incentive/client/cli/tx.go
Kevin Davis 1ef9bd331b
USDX incentives implementation (#399)
* USDX incentives implementation (#399)
* feat: upgrade to cosmos-sdk v0.38

Co-authored-by: Denali Marsh <denali@kava.io>
Co-authored-by: John Maheswaran <jmaheswaran@users.noreply.github.com>
Co-authored-by: John Maheswaran <john@kava.io>
2020-04-24 11:20:34 -04:00

64 lines
1.7 KiB
Go

package cli
import (
"bufio"
"fmt"
"strings"
"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"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/kava-labs/kava/x/incentive/types"
"github.com/spf13/cobra"
)
// GetTxCmd returns the transaction cli commands for the incentive module
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
incentiveTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "transaction commands for the incentive module",
}
incentiveTxCmd.AddCommand(flags.PostCommands(
getCmdClaim(cdc),
)...)
return incentiveTxCmd
}
func getCmdClaim(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "claim [owner] [denom]",
Short: "claim rewards for owner and denom",
Long: strings.TrimSpace(
fmt.Sprintf(`Claim any outstanding rewards owned by owner for the input denom,
Example:
$ %s tx %s claim kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw bnb
`, version.ClientName, types.ModuleName),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
cliCtx := context.NewCLIContext().WithCodec(cdc)
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
owner, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
msg := types.NewMsgClaimReward(owner, args[1])
err = msg.ValidateBasic()
if err != nil {
return err
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}