Skip to content

Commit 6652b67

Browse files
committed
feat!: bring back the cliff vesting command (cosmos#111) cosmos#271
1 parent cc29414 commit 6652b67

File tree

1 file changed

+50
-0
lines changed
  • x/auth/vesting/client/cli

1 file changed

+50
-0
lines changed

x/auth/vesting/client/cli/tx.go

+50
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import (
66
"io/ioutil"
77
"os"
88
"strconv"
9+
"time"
910

1011
"github.com/spf13/cobra"
1112

1213
"github.com/cosmos/cosmos-sdk/client"
1314
"github.com/cosmos/cosmos-sdk/client/flags"
1415
"github.com/cosmos/cosmos-sdk/client/tx"
1516
sdk "github.com/cosmos/cosmos-sdk/types"
17+
"github.com/cosmos/cosmos-sdk/types/errors"
1618
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
1719
)
1820

@@ -40,6 +42,7 @@ func GetTxCmd() *cobra.Command {
4042
NewMsgCreatePermanentLockedAccountCmd(),
4143
NewMsgCreatePeriodicVestingAccountCmd(),
4244
NewMsgCreateClawbackVestingAccountCmd(),
45+
NewMsgCreateCliffVestingAccountCmd(),
4346
NewMsgClawbackCmd(),
4447
)
4548

@@ -377,3 +380,50 @@ func NewMsgClawbackCmd() *cobra.Command {
377380
flags.AddTxFlagsToCmd(cmd)
378381
return cmd
379382
}
383+
384+
// NewMsgCreateDelayedVestingAccountCmd returns a CLI command handler for creating a
385+
// NewMsgCreateDelayedVestingAccountCmd transaction.
386+
// This is hacky, but meant to mitigate the pain of a very specific use case.
387+
// Namely, make it easy to make cliff locks to an address.
388+
func NewMsgCreateCliffVestingAccountCmd() *cobra.Command {
389+
cmd := &cobra.Command{
390+
Use: "create-cliff-vesting-account [to_address] [amount] [cliff_duration]",
391+
Short: "Create a new cliff vesting account funded with an allocation of tokens.",
392+
Long: `Create a new delayed vesting account funded with an allocation of tokens. All vesting accouts created will have their start time
393+
set by the committed block's time. The cliff duration should be specified in hours.`,
394+
Args: cobra.ExactArgs(3),
395+
RunE: func(cmd *cobra.Command, args []string) error {
396+
clientCtx, err := client.GetClientTxContext(cmd)
397+
if err != nil {
398+
return err
399+
}
400+
toAddr, err := sdk.AccAddressFromBech32(args[0])
401+
if err != nil {
402+
return err
403+
}
404+
405+
amount, err := sdk.ParseCoinsNormalized(args[1])
406+
if err != nil {
407+
return err
408+
}
409+
410+
cliffDuration, err := time.ParseDuration(args[2])
411+
if err != nil {
412+
err = errors.Wrap(err, "duration incorrectly formatted, see https://pkg.go.dev/time#ParseDuration")
413+
return err
414+
}
415+
cliffVesting := true
416+
417+
endTime := time.Now().Add(cliffDuration)
418+
endEpochTime := endTime.Unix()
419+
420+
msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endEpochTime, cliffVesting)
421+
422+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
423+
},
424+
}
425+
426+
flags.AddTxFlagsToCmd(cmd)
427+
428+
return cmd
429+
}

0 commit comments

Comments
 (0)