2018-04-25 07:18:06 -07:00
|
|
|
package cli
|
2018-02-24 05:19:32 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-07-02 21:33:53 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2018-04-02 05:05:23 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2018-08-06 11:11:30 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-02-25 15:45:20 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-04-25 07:18:06 -07:00
|
|
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
2018-09-07 10:04:58 -07:00
|
|
|
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
2018-02-25 15:45:20 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
2018-08-06 11:11:30 -07:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2018-02-24 05:19:32 -08:00
|
|
|
)
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdCreateValidator implements the create validator command handler.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command {
|
2018-03-17 09:22:11 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "create-validator",
|
|
|
|
Short: "create new validator initialized with a self-delegation to it",
|
2018-03-17 09:22:11 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-05-08 09:47:31 -07:00
|
|
|
|
2018-07-26 14:41:24 -07:00
|
|
|
amounstStr := viper.GetString(FlagAmount)
|
|
|
|
if amounstStr == "" {
|
|
|
|
return fmt.Errorf("Must specify amount to stake using --amount")
|
|
|
|
}
|
|
|
|
amount, err := sdk.ParseCoin(amounstStr)
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valAddr, err := cliCtx.GetFromAddress()
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-19 12:18:31 -07:00
|
|
|
|
|
|
|
pkStr := viper.GetString(FlagPubKey)
|
|
|
|
if len(pkStr) == 0 {
|
|
|
|
return fmt.Errorf("must use --pubkey flag")
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
pk, err := sdk.GetConsPubKeyBech32(pkStr)
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
if viper.GetString(FlagMoniker) == "" {
|
2018-05-17 08:12:28 -07:00
|
|
|
return fmt.Errorf("please enter a moniker for the validator using --moniker")
|
2018-03-17 09:22:11 -07:00
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
description := stake.Description{
|
|
|
|
Moniker: viper.GetString(FlagMoniker),
|
|
|
|
Identity: viper.GetString(FlagIdentity),
|
|
|
|
Website: viper.GetString(FlagWebsite),
|
|
|
|
Details: viper.GetString(FlagDetails),
|
|
|
|
}
|
2018-07-10 17:16:37 -07:00
|
|
|
|
2018-09-24 15:23:58 -07:00
|
|
|
// get the initial validator commission parameters
|
|
|
|
rateStr := viper.GetString(FlagCommissionRate)
|
|
|
|
maxRateStr := viper.GetString(FlagCommissionMaxRate)
|
|
|
|
maxChangeRateStr := viper.GetString(FlagCommissionMaxChangeRate)
|
|
|
|
commissionMsg, err := buildCommissionMsg(rateStr, maxRateStr, maxChangeRateStr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-10 17:16:37 -07:00
|
|
|
var msg sdk.Msg
|
|
|
|
if viper.GetString(FlagAddressDelegator) != "" {
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator))
|
2018-07-10 17:16:37 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-09-24 15:23:58 -07:00
|
|
|
msg = stake.NewMsgCreateValidatorOnBehalfOf(
|
|
|
|
delAddr, sdk.ValAddress(valAddr), pk, amount, description, commissionMsg,
|
|
|
|
)
|
2018-07-10 17:16:37 -07:00
|
|
|
} else {
|
2018-09-24 15:23:58 -07:00
|
|
|
msg = stake.NewMsgCreateValidator(
|
|
|
|
sdk.ValAddress(valAddr), pk, amount, description, commissionMsg,
|
|
|
|
)
|
2018-07-10 17:16:37 -07:00
|
|
|
}
|
2018-09-24 15:23:58 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-09-24 15:23:58 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-03-17 09:22:11 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().AddFlagSet(fsPk)
|
|
|
|
cmd.Flags().AddFlagSet(fsAmount)
|
2018-07-26 10:41:34 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsDescriptionCreate)
|
2018-09-24 15:23:58 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsCommissionCreate)
|
2018-07-10 17:16:37 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsDelegator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
return cmd
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdEditValidator implements the create edit validator command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
|
2018-03-17 09:22:11 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-05-17 08:12:28 -07:00
|
|
|
Use: "edit-validator",
|
|
|
|
Short: "edit and existing validator account",
|
2018-03-17 09:22:11 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-03-17 09:22:11 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valAddr, err := cliCtx.GetFromAddress()
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
description := stake.Description{
|
|
|
|
Moniker: viper.GetString(FlagMoniker),
|
|
|
|
Identity: viper.GetString(FlagIdentity),
|
|
|
|
Website: viper.GetString(FlagWebsite),
|
|
|
|
Details: viper.GetString(FlagDetails),
|
|
|
|
}
|
2018-08-30 21:06:44 -07:00
|
|
|
|
2018-09-24 15:23:58 -07:00
|
|
|
var newRate *sdk.Dec
|
|
|
|
|
|
|
|
commissionRate := viper.GetString(FlagCommissionRate)
|
|
|
|
if commissionRate != "" {
|
|
|
|
rate, err := sdk.NewDecFromStr(commissionRate)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("invalid new commission rate: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
newRate = &rate
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := stake.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate)
|
2018-03-17 09:22:11 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-09-24 15:23:58 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-03-17 09:22:11 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:41:34 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsDescriptionEdit)
|
2018-09-24 15:23:58 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsCommissionUpdate)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
return cmd
|
|
|
|
}
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdDelegate implements the delegate command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
|
2018-03-17 09:22:11 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "delegate",
|
2018-06-26 19:00:12 -07:00
|
|
|
Short: "delegate liquid tokens to an validator",
|
2018-03-17 09:22:11 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-07-18 23:53:12 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
amount, err := sdk.ParseCoin(viper.GetString(FlagAmount))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, err := cliCtx.GetFromAddress()
|
2018-06-28 10:12:02 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidator))
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
msg := stake.NewMsgDelegate(delAddr, valAddr, amount)
|
2018-02-24 05:19:32 -08:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-03-17 09:22:11 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-03-17 09:22:11 -07:00
|
|
|
},
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsAmount)
|
2018-05-09 21:01:58 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsValidator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
return cmd
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdRedelegate implements the redelegate validator command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
2018-03-17 09:22:11 -07:00
|
|
|
cmd := &cobra.Command{
|
2018-06-26 19:00:12 -07:00
|
|
|
Use: "redelegate",
|
|
|
|
Short: "redelegate illiquid tokens from one validator to another",
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd.AddCommand(
|
2018-07-02 21:33:53 -07:00
|
|
|
client.PostCommands(
|
|
|
|
GetCmdBeginRedelegate(storeName, cdc),
|
|
|
|
GetCmdCompleteRedelegate(cdc),
|
|
|
|
)...)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdBeginRedelegate the begin redelegation command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdBeginRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "begin",
|
|
|
|
Short: "begin redelegation",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
var err error
|
2018-08-30 21:06:44 -07:00
|
|
|
|
|
|
|
delAddr, err := cliCtx.GetFromAddress()
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valSrcAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidatorSrc))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valDstAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidatorDst))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the shares amount
|
|
|
|
sharesAmountStr := viper.GetString(FlagSharesAmount)
|
|
|
|
sharesPercentStr := viper.GetString(FlagSharesPercent)
|
2018-08-06 11:11:30 -07:00
|
|
|
sharesAmount, err := getShares(
|
|
|
|
storeName, cdc, sharesAmountStr, sharesPercentStr,
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, valSrcAddr,
|
2018-08-06 11:11:30 -07:00
|
|
|
)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
msg := stake.NewMsgBeginRedelegate(delAddr, valSrcAddr, valDstAddr, sharesAmount)
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().AddFlagSet(fsShares)
|
|
|
|
cmd.Flags().AddFlagSet(fsRedelegation)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdCompleteRedelegate implements the complete redelegation command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdCompleteRedelegate(cdc *codec.Codec) *cobra.Command {
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "complete",
|
|
|
|
Short: "complete redelegation",
|
2018-03-17 09:22:11 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-03-17 09:22:11 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, err := cliCtx.GetFromAddress()
|
2018-06-28 10:12:02 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valSrcAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidatorSrc))
|
2018-06-28 10:12:02 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valDstAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidatorDst))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
msg := stake.NewMsgCompleteRedelegate(delAddr, valSrcAddr, valDstAddr)
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsRedelegation)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdUnbond implements the unbond validator command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "unbond",
|
|
|
|
Short: "begin or complete unbonding shares from a validator",
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd.AddCommand(
|
2018-07-02 21:33:53 -07:00
|
|
|
client.PostCommands(
|
|
|
|
GetCmdBeginUnbonding(storeName, cdc),
|
|
|
|
GetCmdCompleteUnbonding(cdc),
|
|
|
|
)...)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdBeginUnbonding implements the begin unbonding validator command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdBeginUnbonding(storeName string, cdc *codec.Codec) *cobra.Command {
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "begin",
|
|
|
|
Short: "begin unbonding",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, err := cliCtx.GetFromAddress()
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidator))
|
2018-03-17 09:22:11 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
// get the shares amount
|
|
|
|
sharesAmountStr := viper.GetString(FlagSharesAmount)
|
|
|
|
sharesPercentStr := viper.GetString(FlagSharesPercent)
|
2018-08-06 11:11:30 -07:00
|
|
|
sharesAmount, err := getShares(
|
|
|
|
storeName, cdc, sharesAmountStr, sharesPercentStr,
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, valAddr,
|
2018-08-06 11:11:30 -07:00
|
|
|
)
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
msg := stake.NewMsgBeginUnbonding(delAddr, valAddr, sharesAmount)
|
2018-03-17 09:22:11 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-03-17 09:22:11 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-03-17 09:22:11 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().AddFlagSet(fsShares)
|
2018-05-09 21:01:58 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsValidator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-03-17 09:22:11 -07:00
|
|
|
return cmd
|
2018-02-24 05:19:32 -08:00
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-06 11:11:30 -07:00
|
|
|
// GetCmdCompleteUnbonding implements the complete unbonding validator command.
|
2018-09-13 11:17:32 -07:00
|
|
|
func GetCmdCompleteUnbonding(cdc *codec.Codec) *cobra.Command {
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "complete",
|
|
|
|
Short: "complete unbonding",
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-09-07 10:15:49 -07:00
|
|
|
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
2018-08-06 11:11:30 -07:00
|
|
|
cliCtx := context.NewCLIContext().
|
|
|
|
WithCodec(cdc).
|
|
|
|
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
delAddr, err := cliCtx.GetFromAddress()
|
2018-06-28 10:12:02 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
valAddr, err := sdk.ValAddressFromBech32(viper.GetString(FlagAddressValidator))
|
2018-06-26 19:00:12 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-08-30 21:06:44 -07:00
|
|
|
msg := stake.NewMsgCompleteUnbonding(delAddr, valAddr)
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-09-02 11:20:14 -07:00
|
|
|
if cliCtx.GenerateOnly {
|
2018-09-07 10:15:49 -07:00
|
|
|
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-09-02 11:20:14 -07:00
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
// build and sign the transaction, then broadcast to Tendermint
|
2018-09-26 06:29:39 -07:00
|
|
|
return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg})
|
2018-06-26 19:00:12 -07:00
|
|
|
},
|
|
|
|
}
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
cmd.Flags().AddFlagSet(fsValidator)
|
2018-08-06 11:11:30 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
return cmd
|
|
|
|
}
|