cosmos-sdk/x/staking/client/cli/tx.go

375 lines
12 KiB
Go
Raw Normal View History

2018-04-25 07:18:06 -07:00
package cli
2018-02-24 05:19:32 -08:00
import (
"fmt"
"os"
2019-02-06 16:15:37 -08:00
"strings"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
2018-08-06 11:11:30 -07:00
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
2018-02-25 15:45:20 -08:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/cosmos/cosmos-sdk/x/staking/types"
2018-02-24 05:19:32 -08:00
)
2018-08-06 11:11:30 -07:00
// GetCmdCreateValidator implements the create validator command handler.
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 {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
2018-08-06 11:11:30 -07:00
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
txBldr, msg, err := BuildCreateValidatorMsg(cliCtx, txBldr)
if err != nil {
return err
}
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
2018-03-17 09:22:11 -07:00
},
}
cmd.Flags().AddFlagSet(FsPk)
cmd.Flags().AddFlagSet(FsAmount)
cmd.Flags().AddFlagSet(fsDescriptionCreate)
cmd.Flags().AddFlagSet(FsCommissionCreate)
2019-02-08 12:44:19 -08:00
cmd.Flags().AddFlagSet(FsMinSelfDelegation)
2019-02-06 16:15:37 -08:00
cmd.Flags().String(FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", client.FlagGenerateOnly))
cmd.Flags().String(FlagNodeID, "", "The node's ID")
cmd.MarkFlagRequired(client.FlagFrom)
cmd.MarkFlagRequired(FlagAmount)
cmd.MarkFlagRequired(FlagPubKey)
cmd.MarkFlagRequired(FlagMoniker)
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.
2019-02-06 16:15:37 -08:00
// TODO: add full description
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 an existing validator account",
2018-03-17 09:22:11 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
2018-08-06 11:11:30 -07:00
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
2018-03-17 09:22:11 -07:00
valAddr := cliCtx.GetFromAddress()
description := types.Description{
2018-03-17 09:22:11 -07:00
Moniker: viper.GetString(FlagMoniker),
Identity: viper.GetString(FlagIdentity),
Website: viper.GetString(FlagWebsite),
Details: viper.GetString(FlagDetails),
}
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
}
2019-02-08 12:44:19 -08:00
var newMinSelfDelegation *sdk.Int
minSelfDelegationString := viper.GetString(FlagMinSelfDelegation)
if minSelfDelegationString != "" {
msb, ok := sdk.NewIntFromString(minSelfDelegationString)
if !ok {
return fmt.Errorf(types.ErrMinSelfDelegationInvalid(types.DefaultCodespace).Error())
2019-02-08 12:44:19 -08:00
}
newMinSelfDelegation = &msb
}
msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation)
2019-02-08 12:44:19 -08:00
// build and sign the transaction, then broadcast to Tendermint
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
2018-03-17 09:22:11 -07:00
},
}
cmd.Flags().AddFlagSet(fsDescriptionEdit)
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.
func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
2019-02-06 16:15:37 -08:00
return &cobra.Command{
Use: "delegate [validator-addr] [amount]",
Args: cobra.ExactArgs(2),
Short: "Delegate liquid tokens to a validator",
Long: strings.TrimSpace(
fmt.Sprintf(`Delegate an amount of liquid coins to a validator from your wallet.
Example:
$ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey
`,
version.ClientName,
),
),
2018-03-17 09:22:11 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
2018-08-06 11:11:30 -07:00
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
2019-02-06 16:15:37 -08:00
amount, err := sdk.ParseCoin(args[1])
2018-03-17 09:22:11 -07:00
if err != nil {
return err
}
2018-02-24 05:19:32 -08:00
delAddr := cliCtx.GetFromAddress()
2019-02-06 16:15:37 -08:00
valAddr, err := sdk.ValAddressFromBech32(args[0])
2018-03-17 09:22:11 -07:00
if err != nil {
return err
}
2018-02-24 05:19:32 -08:00
msg := types.NewMsgDelegate(delAddr, valAddr, amount)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
2018-03-17 09:22:11 -07:00
},
2018-02-24 05:19:32 -08:00
}
}
2018-11-12 13:01:00 -08:00
// GetCmdRedelegate the begin redelegation command.
func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
2019-02-06 16:15:37 -08:00
return &cobra.Command{
Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]",
Short: "Redelegate illiquid tokens from one validator to another",
2019-02-06 16:15:37 -08:00
Args: cobra.ExactArgs(3),
Long: strings.TrimSpace(
fmt.Sprintf(`Redelegate an amount of illiquid staking tokens from one validator to another.
Example:
$ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 100stake --from mykey
`,
version.ClientName,
),
),
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
2018-08-06 11:11:30 -07:00
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
delAddr := cliCtx.GetFromAddress()
2019-02-06 16:15:37 -08:00
valSrcAddr, err := sdk.ValAddressFromBech32(args[0])
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
if err != nil {
return err
}
2018-08-06 11:11:30 -07:00
2019-02-06 16:15:37 -08:00
valDstAddr, err := sdk.ValAddressFromBech32(args[1])
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
if err != nil {
return err
}
amount, err := sdk.ParseCoin(args[2])
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
if err != nil {
return err
}
msg := types.NewMsgBeginRedelegate(delAddr, valSrcAddr, valDstAddr, amount)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
},
}
}
2018-08-06 11:11:30 -07:00
// GetCmdUnbond implements the unbond validator command.
func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
2019-02-06 16:15:37 -08:00
return &cobra.Command{
Use: "unbond [validator-addr] [amount]",
Short: "Unbond shares from a validator",
2019-02-06 16:15:37 -08:00
Args: cobra.ExactArgs(2),
Long: strings.TrimSpace(
fmt.Sprintf(`Unbond an amount of bonded shares from a validator.
Example:
$ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey
`,
version.ClientName,
),
),
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(auth.DefaultTxEncoder(cdc))
2018-08-06 11:11:30 -07:00
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
delAddr := cliCtx.GetFromAddress()
2019-02-06 16:15:37 -08:00
valAddr, err := sdk.ValAddressFromBech32(args[0])
2018-03-17 09:22:11 -07:00
if err != nil {
return err
}
amount, err := sdk.ParseCoin(args[1])
Merge PR #1119: Unbonding, Redelegation * stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
2018-06-26 19:00:12 -07:00
if err != nil {
return err
}
msg := types.NewMsgUndelegate(delAddr, valAddr, amount)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
2018-03-17 09:22:11 -07:00
},
}
2018-02-24 05:19:32 -08:00
}
//__________________________________________________________
var (
defaultTokens = sdk.TokensFromTendermintPower(100)
defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom
defaultCommissionRate = "0.1"
defaultCommissionMaxRate = "0.2"
defaultCommissionMaxChangeRate = "0.01"
defaultMinSelfDelegation = "1"
)
// Return the flagset, particular flags, and a description of defaults
// this is anticipated to be used with the gen-tx
func CreateValidatorMsgHelpers(ipDefault string) (fs *flag.FlagSet, nodeIDFlag, pubkeyFlag, amountFlag, defaultsDesc string) {
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
fsCreateValidator.String(FlagNodeID, "", "The node's NodeID")
fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website")
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
fsCreateValidator.String(FlagIdentity, "", "The (optional) identity signature (ex. UPort or Keybase)")
fsCreateValidator.AddFlagSet(FsCommissionCreate)
fsCreateValidator.AddFlagSet(FsMinSelfDelegation)
fsCreateValidator.AddFlagSet(FsAmount)
fsCreateValidator.AddFlagSet(FsPk)
defaultsDesc = fmt.Sprintf(`
delegation amount: %s
commission rate: %s
commission max rate: %s
commission max change rate: %s
minimum self delegation: %s
`, defaultAmount, defaultCommissionRate,
defaultCommissionMaxRate, defaultCommissionMaxChangeRate,
defaultMinSelfDelegation)
return fsCreateValidator, FlagNodeID, FlagPubKey, FlagAmount, defaultsDesc
}
// prepare flags in config
func PrepareFlagsForTxCreateValidator(
config *cfg.Config, nodeID, chainID string, valPubKey crypto.PubKey,
) {
ip := viper.GetString(FlagIP)
if ip == "" {
fmt.Fprintf(os.Stderr, "couldn't retrieve an external IP; "+
"the tx's memo field will be unset")
}
website := viper.GetString(FlagWebsite)
details := viper.GetString(FlagDetails)
identity := viper.GetString(FlagIdentity)
viper.Set(client.FlagChainID, chainID)
viper.Set(client.FlagFrom, viper.GetString(client.FlagName))
viper.Set(FlagNodeID, nodeID)
viper.Set(FlagIP, ip)
viper.Set(FlagPubKey, sdk.MustBech32ifyConsPub(valPubKey))
viper.Set(FlagMoniker, config.Moniker)
viper.Set(FlagWebsite, website)
viper.Set(FlagDetails, details)
viper.Set(FlagIdentity, identity)
if config.Moniker == "" {
viper.Set(FlagMoniker, viper.GetString(client.FlagName))
}
if viper.GetString(FlagAmount) == "" {
viper.Set(FlagAmount, defaultAmount)
}
if viper.GetString(FlagCommissionRate) == "" {
viper.Set(FlagCommissionRate, defaultCommissionRate)
}
if viper.GetString(FlagCommissionMaxRate) == "" {
viper.Set(FlagCommissionMaxRate, defaultCommissionMaxRate)
}
if viper.GetString(FlagCommissionMaxChangeRate) == "" {
viper.Set(FlagCommissionMaxChangeRate, defaultCommissionMaxChangeRate)
}
if viper.GetString(FlagMinSelfDelegation) == "" {
viper.Set(FlagMinSelfDelegation, defaultMinSelfDelegation)
}
}
// BuildCreateValidatorMsg makes a new MsgCreateValidator.
func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr authtxb.TxBuilder) (authtxb.TxBuilder, sdk.Msg, error) {
amounstStr := viper.GetString(FlagAmount)
amount, err := sdk.ParseCoin(amounstStr)
if err != nil {
return txBldr, nil, err
}
valAddr := cliCtx.GetFromAddress()
pkStr := viper.GetString(FlagPubKey)
pk, err := sdk.GetConsPubKeyBech32(pkStr)
if err != nil {
return txBldr, nil, err
}
description := types.NewDescription(
viper.GetString(FlagMoniker),
viper.GetString(FlagIdentity),
viper.GetString(FlagWebsite),
viper.GetString(FlagDetails),
)
// 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 txBldr, nil, err
}
2019-02-08 12:44:19 -08:00
// get the initial validator min self delegation
msbStr := viper.GetString(FlagMinSelfDelegation)
minSelfDelegation, ok := sdk.NewIntFromString(msbStr)
if !ok {
return txBldr, nil, fmt.Errorf(types.ErrMinSelfDelegationInvalid(types.DefaultCodespace).Error())
2019-02-08 12:44:19 -08:00
}
msg := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionMsg, minSelfDelegation,
)
2019-02-06 16:15:37 -08:00
if viper.GetBool(client.FlagGenerateOnly) {
ip := viper.GetString(FlagIP)
nodeID := viper.GetString(FlagNodeID)
if nodeID != "" && ip != "" {
txBldr = txBldr.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip))
}
}
return txBldr, msg, nil
}