Skip to content

Commit

Permalink
feat(cliff): add vesting-cliff-time flags on add-genesis account cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Oct 4, 2022
1 parent 434d418 commit ea3e2c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions cmd/okp4d/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import (
const (
flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time"
flagVestingCliff = "vesting-cliff-time"
flagVestingAmt = "vesting-amount"
)

// AddGenesisAccountCmd returns add-genesis-account cobra Command.
//
//nolint:funlen,gocognit,cyclop
func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Expand Down Expand Up @@ -80,6 +83,10 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
if err != nil {
return err
}
vestingCliff, err := cmd.Flags().GetInt64(flagVestingCliff)
if err != nil {
return err
}
vestingEnd, err := cmd.Flags().GetInt64(flagVestingEnd)
if err != nil {
return err
Expand Down Expand Up @@ -109,14 +116,15 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
}

switch {
case vestingStart != 0 && vestingCliff != 0:
genAccount = authvesting.NewCliffVestingAccountRaw(baseVestingAccount, vestingStart, vestingCliff)
case vestingStart != 0 && vestingEnd != 0:
genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)

case vestingEnd != 0:
genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount)

default:
return errors.New("invalid vesting parameters; must supply start and end time or end time")
return errors.New("invalid vesting parameters; must supply start and end time, start and cliff time or end time")
}
} else {
genAccount = baseAccount
Expand Down Expand Up @@ -187,6 +195,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
cmd.Flags().Int64(flagVestingCliff, 0, "schedule cliff time (unix epoch) for vesting accounts")
flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down
6 changes: 3 additions & 3 deletions x/vesting/types/vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,13 @@ func (cva CliffVestingAccount) GetCliffTime() int64 {
// Validate checks for errors on the account fields.
func (cva CliffVestingAccount) Validate() error {
if cva.GetStartTime() >= cva.GetEndTime() {
return errors.New("vesting start-time cannot be before end-time")
return errors.New("vesting start-time cannot be after end-time")
}
if cva.GetStartTime() >= cva.GetCliffTime() {
return errors.New("vesting start-time cannot be before cliff-time")
return errors.New("vesting start-time cannot be after cliff-time")
}
if cva.GetCliffTime() >= cva.GetEndTime() {
return errors.New("vesting cliff-time cannot be before end-time")
return errors.New("vesting cliff-time cannot be after end-time")
}

return cva.BaseVestingAccount.Validate()
Expand Down

0 comments on commit ea3e2c5

Please sign in to comment.