Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bring back the cliff vesting command (#111) #271

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"strconv"
"time"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -36,6 +37,7 @@ func GetTxCmd() *cobra.Command {

txCmd.AddCommand(
NewMsgCreateVestingAccountCmd(),
NewMsgCreateCliffVestingAccountCmd(),
NewMsgCreateClawbackVestingAccountCmd(),
NewMsgClawbackCmd(),
)
Expand Down Expand Up @@ -261,3 +263,50 @@ func NewMsgClawbackCmd() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// NewMsgCreateDelayedVestingAccountCmd returns a CLI command handler for creating a
// NewMsgCreateDelayedVestingAccountCmd transaction.
// This is hacky, but meant to mitigate the pain of a very specific use case.
// Namely, make it easy to make cliff locks to an address.
func NewMsgCreateCliffVestingAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-cliff-vesting-account [to_address] [amount] [cliff_duration]",
Short: "Create a new cliff vesting account funded with an allocation of tokens.",
Long: `Create a new delayed vesting account funded with an allocation of tokens. All vesting accouts created will have their start time
set by the committed block's time. The cliff duration should be specified in hours.`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
toAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

amount, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}

cliffDuration, err := time.ParseDuration(args[2])
if err != nil {
fmt.Println("duration incorrectly formatted, see https://pkg.go.dev/time#ParseDuration")
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved
return err
}
cliffVesting := true
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

endTime := time.Now().Add(cliffDuration)
endEpochTime := endTime.Unix()

msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endEpochTime, cliffVesting)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}