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

542 lines
14 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/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
2018-02-25 15:45:20 -08:00
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
2018-02-24 05:19:32 -08:00
)
var (
defaultTokens = sdk.TokensFromConsensusPower(100)
defaultAmount = defaultTokens.String() + sdk.DefaultBondDenom
defaultCommissionRate = "0.1"
defaultCommissionMaxRate = "0.2"
defaultCommissionMaxChangeRate = "0.01"
defaultMinSelfDelegation = "1"
)
// NewTxCmd returns a root CLI command handler for all x/staking transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
stakingTxCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Staking transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
stakingTxCmd.AddCommand(flags.PostCommands(
NewCreateValidatorCmd(clientCtx),
NewEditValidatorCmd(clientCtx),
NewDelegateCmd(clientCtx),
NewRedelegateCmd(clientCtx),
NewUnbondCmd(clientCtx),
)...)
return stakingTxCmd
}
func NewCreateValidatorCmd(clientCtx client.Context) *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 {
clientCtx.WithInput(cmd.InOrStdin())
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxGenerator(clientCtx.TxGenerator).WithAccountRetriever(clientCtx.AccountRetriever)
txf, msg, err := NewBuildCreateValidatorMsg(clientCtx, txf, cmd.Flags())
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
2018-03-17 09:22:11 -07:00
},
}
cmd.Flags().AddFlagSet(FlagSetPublicKey())
cmd.Flags().AddFlagSet(FlagSetAmount())
cmd.Flags().AddFlagSet(flagSetDescriptionCreate())
cmd.Flags().AddFlagSet(FlagSetCommissionCreate())
cmd.Flags().AddFlagSet(FlagSetMinSelfDelegation())
cmd.Flags().String(FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", flags.FlagGenerateOnly))
cmd.Flags().String(FlagNodeID, "", "The node's ID")
_ = cmd.MarkFlagRequired(flags.FlagFrom)
_ = cmd.MarkFlagRequired(FlagAmount)
_ = cmd.MarkFlagRequired(FlagPubKey)
_ = cmd.MarkFlagRequired(FlagMoniker)
return cmd
2018-02-24 05:19:32 -08:00
}
func NewEditValidatorCmd(clientCtx client.Context) *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 {
clientCtx := clientCtx.WithInput(cmd.InOrStdin())
2018-03-17 09:22:11 -07:00
valAddr := clientCtx.GetFromAddress()
moniker, _ := cmd.Flags().GetString(FlagMoniker)
identity, _ := cmd.Flags().GetString(FlagIdentity)
website, _ := cmd.Flags().GetString(FlagWebsite)
security, _ := cmd.Flags().GetString(FlagSecurityContact)
details, _ := cmd.Flags().GetString(FlagDetails)
description := types.NewDescription(
moniker,
identity,
website,
security,
details,
)
var newRate *sdk.Dec
commissionRate, _ := cmd.Flags().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, _ := cmd.Flags().GetString(FlagMinSelfDelegation)
2019-02-08 12:44:19 -08:00
if minSelfDelegationString != "" {
msb, ok := sdk.NewIntFromString(minSelfDelegationString)
if !ok {
return types.ErrMinSelfDelegationInvalid
2019-02-08 12:44:19 -08:00
}
2019-02-08 12:44:19 -08:00
newMinSelfDelegation = &msb
}
msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation)
2020-04-09 07:00:10 -07:00
if err := msg.ValidateBasic(); err != nil {
return err
}
2019-02-08 12:44:19 -08:00
// build and sign the transaction, then broadcast to Tendermint
return tx.GenerateOrBroadcastTx(clientCtx, msg)
2018-03-17 09:22:11 -07:00
},
}
cmd.Flags().AddFlagSet(flagSetDescriptionEdit())
cmd.Flags().AddFlagSet(flagSetCommissionUpdate())
cmd.Flags().AddFlagSet(FlagSetMinSelfDelegation())
return cmd
2018-03-17 09:22:11 -07:00
}
2018-02-24 05:19:32 -08:00
func NewDelegateCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
2019-02-06 16:15:37 -08:00
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.AppName,
),
),
2018-03-17 09:22:11 -07:00
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := clientCtx.InitWithInput(cmd.InOrStdin())
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 := clientCtx.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)
2020-04-09 07:00:10 -07:00
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
2018-03-17 09:22:11 -07:00
},
2018-02-24 05:19:32 -08:00
}
return cmd
2018-02-24 05:19:32 -08:00
}
func NewRedelegateCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
2019-02-06 16:15:37 -08:00
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.AppName,
),
),
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 {
clientCtx := clientCtx.InitWithInput(cmd.InOrStdin())
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 := clientCtx.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)
2020-04-09 07:00:10 -07:00
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, 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
},
}
return cmd
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
}
func NewUnbondCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
2019-02-06 16:15:37 -08:00
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.AppName,
),
),
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 {
clientCtx := clientCtx.InitWithInput(cmd.InOrStdin())
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 := clientCtx.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)
2020-04-09 07:00:10 -07:00
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTx(clientCtx, msg)
2018-03-17 09:22:11 -07:00
},
}
return cmd
2018-02-24 05:19:32 -08:00
}
func NewBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet) (tx.Factory, sdk.Msg, error) {
fAmount, _ := fs.GetString(FlagAmount)
amount, err := sdk.ParseCoin(fAmount)
if err != nil {
return txf, nil, err
}
valAddr := clientCtx.GetFromAddress()
pkStr, _ := fs.GetString(FlagPubKey)
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pkStr)
if err != nil {
return txf, nil, err
}
moniker, _ := fs.GetString(FlagMoniker)
identity, _ := fs.GetString(FlagIdentity)
website, _ := fs.GetString(FlagWebsite)
security, _ := fs.GetString(FlagSecurityContact)
details, _ := fs.GetString(FlagDetails)
description := types.NewDescription(
moniker,
identity,
website,
security,
details,
)
// get the initial validator commission parameters
rateStr, _ := fs.GetString(FlagCommissionRate)
maxRateStr, _ := fs.GetString(FlagCommissionMaxRate)
maxChangeRateStr, _ := fs.GetString(FlagCommissionMaxChangeRate)
commissionRates, err := buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr)
if err != nil {
return txf, nil, err
}
// get the initial validator min self delegation
msbStr, _ := fs.GetString(FlagMinSelfDelegation)
minSelfDelegation, ok := sdk.NewIntFromString(msbStr)
if !ok {
return txf, nil, types.ErrMinSelfDelegationInvalid
}
msg := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
)
2020-04-09 07:00:10 -07:00
if err := msg.ValidateBasic(); err != nil {
return txf, nil, err
}
genOnly, _ := fs.GetBool(flags.FlagGenerateOnly)
if genOnly {
ip, _ := fs.GetString(FlagIP)
nodeID, _ := fs.GetString(FlagNodeID)
if nodeID != "" && ip != "" {
txf = txf.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip))
}
}
return txf, msg, nil
}
// Return the flagset, particular flags, and a description of defaults
// this is anticipated to be used with the gen-tx
func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc string) {
fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError)
fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP")
fsCreateValidator.String(FlagNodeID, "", "The node's NodeID")
2020-07-08 10:57:45 -07:00
fsCreateValidator.String(FlagMoniker, "", "The validator's (optional) moniker")
fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website")
fsCreateValidator.String(FlagSecurityContact, "", "The validator's (optional) security contact email")
fsCreateValidator.String(FlagDetails, "", "The validator's (optional) details")
fsCreateValidator.String(FlagIdentity, "", "The (optional) identity signature (ex. UPort or Keybase)")
fsCreateValidator.AddFlagSet(FlagSetCommissionCreate())
fsCreateValidator.AddFlagSet(FlagSetMinSelfDelegation())
fsCreateValidator.AddFlagSet(FlagSetAmount())
fsCreateValidator.AddFlagSet(FlagSetPublicKey())
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, defaultsDesc
}
type TxCreateValidatorConfig struct {
ChainID string
NodeID string
Moniker string
Amount string
CommissionRate string
CommissionMaxRate string
CommissionMaxChangeRate string
MinSelfDelegation string
TrustNode bool
PubKey string
IP string
Website string
SecurityContact string
Details string
Identity string
}
2020-07-08 10:57:45 -07:00
func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, chainID string, valPubKey crypto.PubKey) (TxCreateValidatorConfig, error) {
c := TxCreateValidatorConfig{}
ip, err := flagSet.GetString(FlagIP)
if err != nil {
return c, err
}
if ip == "" {
_, _ = fmt.Fprintf(os.Stderr, "couldn't retrieve an external IP; "+
"the tx's memo field will be unset")
}
c.IP = ip
website, err := flagSet.GetString(FlagWebsite)
if err != nil {
return c, err
}
c.Website = website
securityContact, err := flagSet.GetString(FlagSecurityContact)
if err != nil {
return c, err
}
c.SecurityContact = securityContact
details, err := flagSet.GetString(FlagDetails)
if err != nil {
return c, err
}
c.SecurityContact = details
identity, err := flagSet.GetString(FlagIdentity)
if err != nil {
return c, err
}
c.Identity = identity
c.Amount, err = flagSet.GetString(FlagAmount)
if err != nil {
return c, err
}
c.CommissionRate, err = flagSet.GetString(FlagCommissionRate)
if err != nil {
return c, err
}
c.CommissionMaxRate, err = flagSet.GetString(FlagCommissionMaxRate)
if err != nil {
return c, err
}
c.CommissionMaxChangeRate, err = flagSet.GetString(FlagCommissionMaxChangeRate)
if err != nil {
return c, err
}
c.MinSelfDelegation, err = flagSet.GetString(FlagMinSelfDelegation)
if err != nil {
return c, err
}
c.NodeID = nodeID
c.TrustNode = true
c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
c.Website = website
c.SecurityContact = securityContact
c.Details = details
c.Identity = identity
2020-07-08 10:57:45 -07:00
c.ChainID = chainID
c.Moniker = moniker
if c.Amount == "" {
c.Amount = defaultAmount
}
if c.CommissionRate == "" {
c.CommissionRate = defaultCommissionRate
}
if c.CommissionMaxRate == "" {
c.CommissionMaxRate = defaultCommissionMaxRate
}
if c.CommissionMaxChangeRate == "" {
c.CommissionMaxChangeRate = defaultCommissionMaxChangeRate
}
if c.MinSelfDelegation == "" {
c.MinSelfDelegation = defaultMinSelfDelegation
}
return c, nil
}
// BuildCreateValidatorMsg makes a new MsgCreateValidator.
func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorConfig, txBldr authtypes.TxBuilder, generateOnly bool) (authtypes.TxBuilder, sdk.Msg, error) {
amounstStr := config.Amount
amount, err := sdk.ParseCoin(amounstStr)
if err != nil {
return txBldr, nil, err
}
valAddr := clientCtx.GetFromAddress()
pkStr := config.PubKey
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pkStr)
if err != nil {
return txBldr, nil, err
}
description := types.NewDescription(
config.Moniker,
config.Identity,
config.Website,
config.SecurityContact,
config.Details,
)
// get the initial validator commission parameters
rateStr := config.CommissionRate
maxRateStr := config.CommissionMaxRate
maxChangeRateStr := config.CommissionMaxChangeRate
commissionRates, err := buildCommissionRates(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 := config.MinSelfDelegation
2019-02-08 12:44:19 -08:00
minSelfDelegation, ok := sdk.NewIntFromString(msbStr)
2019-02-08 12:44:19 -08:00
if !ok {
return txBldr, nil, types.ErrMinSelfDelegationInvalid
2019-02-08 12:44:19 -08:00
}
msg := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
)
if generateOnly {
ip := config.IP
nodeID := config.NodeID
if nodeID != "" && ip != "" {
txBldr = txBldr.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip))
}
}
return txBldr, msg, nil
}