do-not-modify in defaults for edit-validator cli

This commit is contained in:
rigelrozanski 2018-07-26 13:41:34 -04:00
parent 58afe9780b
commit 07705444fd
3 changed files with 27 additions and 19 deletions

View File

@ -2,6 +2,8 @@ package cli
import ( import (
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
"github.com/cosmos/cosmos-sdk/x/stake/types"
) )
// nolint // nolint
@ -23,13 +25,14 @@ const (
// common flagsets to add to various functions // common flagsets to add to various functions
var ( var (
fsPk = flag.NewFlagSet("", flag.ContinueOnError) fsPk = flag.NewFlagSet("", flag.ContinueOnError)
fsAmount = flag.NewFlagSet("", flag.ContinueOnError) fsAmount = flag.NewFlagSet("", flag.ContinueOnError)
fsShares = flag.NewFlagSet("", flag.ContinueOnError) fsShares = flag.NewFlagSet("", flag.ContinueOnError)
fsDescription = flag.NewFlagSet("", flag.ContinueOnError) fsDescriptionCreate = flag.NewFlagSet("", flag.ContinueOnError)
fsValidator = flag.NewFlagSet("", flag.ContinueOnError) fsDescriptionEdit = flag.NewFlagSet("", flag.ContinueOnError)
fsDelegator = flag.NewFlagSet("", flag.ContinueOnError) fsValidator = flag.NewFlagSet("", flag.ContinueOnError)
fsRedelegation = flag.NewFlagSet("", flag.ContinueOnError) fsDelegator = flag.NewFlagSet("", flag.ContinueOnError)
fsRedelegation = flag.NewFlagSet("", flag.ContinueOnError)
) )
func init() { func init() {
@ -37,10 +40,14 @@ func init() {
fsAmount.String(FlagAmount, "1steak", "Amount of coins to bond") fsAmount.String(FlagAmount, "1steak", "Amount of coins to bond")
fsShares.String(FlagSharesAmount, "", "Amount of source-shares to either unbond or redelegate as a positive integer or decimal") fsShares.String(FlagSharesAmount, "", "Amount of source-shares to either unbond or redelegate as a positive integer or decimal")
fsShares.String(FlagSharesPercent, "", "Percent of source-shares to either unbond or redelegate as a positive integer or decimal >0 and <=1") fsShares.String(FlagSharesPercent, "", "Percent of source-shares to either unbond or redelegate as a positive integer or decimal >0 and <=1")
fsDescription.String(FlagMoniker, "", "validator name") fsDescriptionCreate.String(FlagMoniker, "", "validator name")
fsDescription.String(FlagIdentity, "", "optional identity signature (ex. UPort or Keybase)") fsDescriptionCreate.String(FlagIdentity, "", "optional identity signature (ex. UPort or Keybase)")
fsDescription.String(FlagWebsite, "", "optional website") fsDescriptionCreate.String(FlagWebsite, "", "optional website")
fsDescription.String(FlagDetails, "", "optional details") fsDescriptionCreate.String(FlagDetails, "", "optional details")
fsDescriptionEdit.String(FlagMoniker, types.DoNotModifyDesc, "validator name")
fsDescriptionEdit.String(FlagIdentity, types.DoNotModifyDesc, "optional identity signature (ex. UPort or Keybase)")
fsDescriptionEdit.String(FlagWebsite, types.DoNotModifyDesc, "optional website")
fsDescriptionEdit.String(FlagDetails, types.DoNotModifyDesc, "optional details")
fsValidator.String(FlagAddressValidator, "", "hex address of the validator") fsValidator.String(FlagAddressValidator, "", "hex address of the validator")
fsDelegator.String(FlagAddressDelegator, "", "hex address of the delegator") fsDelegator.String(FlagAddressDelegator, "", "hex address of the delegator")
fsRedelegation.String(FlagAddressValidatorSrc, "", "hex address of the source validator") fsRedelegation.String(FlagAddressValidatorSrc, "", "hex address of the source validator")

View File

@ -73,7 +73,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command {
cmd.Flags().AddFlagSet(fsPk) cmd.Flags().AddFlagSet(fsPk)
cmd.Flags().AddFlagSet(fsAmount) cmd.Flags().AddFlagSet(fsAmount)
cmd.Flags().AddFlagSet(fsDescription) cmd.Flags().AddFlagSet(fsDescriptionCreate)
cmd.Flags().AddFlagSet(fsDelegator) cmd.Flags().AddFlagSet(fsDelegator)
return cmd return cmd
} }
@ -108,7 +108,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command {
}, },
} }
cmd.Flags().AddFlagSet(fsDescription) cmd.Flags().AddFlagSet(fsDescriptionEdit)
return cmd return cmd
} }

View File

@ -13,8 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/wire"
) )
const doNotModifyDescVal = "[do-not-modify]"
// Validator defines the total amount of bond shares and their exchange rate to // Validator defines the total amount of bond shares and their exchange rate to
// coins. Accumulation of interest is modelled as an in increase in the // coins. Accumulation of interest is modelled as an in increase in the
// exchange rate, and slashing as a decrease. When coins are delegated to this // exchange rate, and slashing as a decrease. When coins are delegated to this
@ -250,6 +248,9 @@ func (v Validator) Equal(c2 Validator) bool {
v.LastBondedTokens.Equal(c2.LastBondedTokens) v.LastBondedTokens.Equal(c2.LastBondedTokens)
} }
// constant used in flags to indicate that description field should not be updated
const DoNotModifyDesc = "[do-not-modify]"
// Description - description fields for a validator // Description - description fields for a validator
type Description struct { type Description struct {
Moniker string `json:"moniker"` // name Moniker string `json:"moniker"` // name
@ -271,16 +272,16 @@ func NewDescription(moniker, identity, website, details string) Description {
// UpdateDescription updates the fields of a given description. An error is // UpdateDescription updates the fields of a given description. An error is
// returned if the resulting description contains an invalid length. // returned if the resulting description contains an invalid length.
func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error) { func (d Description) UpdateDescription(d2 Description) (Description, sdk.Error) {
if d2.Moniker == doNotModifyDescVal { if d2.Moniker == DoNotModifyDesc {
d2.Moniker = d.Moniker d2.Moniker = d.Moniker
} }
if d2.Identity == doNotModifyDescVal { if d2.Identity == DoNotModifyDesc {
d2.Identity = d.Identity d2.Identity = d.Identity
} }
if d2.Website == doNotModifyDescVal { if d2.Website == DoNotModifyDesc {
d2.Website = d.Website d2.Website = d.Website
} }
if d2.Details == doNotModifyDescVal { if d2.Details == DoNotModifyDesc {
d2.Details = d.Details d2.Details = d.Details
} }