/
tx_create_vesting_account.go
80 lines (67 loc) · 1.88 KB
/
tx_create_vesting_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cli
import (
"strconv"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/public-awesome/stargaze/v5/x/alloc/types"
)
var _ = strconv.Itoa(0)
// Transaction command flags
const (
FlagDelayed = "delayed"
)
func CmdCreateVestingAccount() *cobra.Command {
cmd := &cobra.Command{
Use: "create-vesting-account [to_address] [amount] [start_time] [end_time]",
Short: "Create a new vesting account funded with an allocation of tokens.",
Long: `Create a new vesting account funded with an allocation of tokens. The
account can either be a delayed or continuous vesting account, which is determined
by the '--delayed' flag. The start_time, end_time must be provided as a UNIX epoch
timestamp.`,
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) (err 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
}
startTime, err := strconv.ParseInt(args[2], 10, 64)
if err != nil {
return err
}
endTime, err := strconv.ParseInt(args[3], 10, 64)
if err != nil {
return err
}
delayed, err := cmd.Flags().GetBool(FlagDelayed)
if err != nil {
return err
}
msg := types.NewMsgCreateVestingAccount(
clientCtx.GetFromAddress(),
toAddr,
amount,
startTime,
endTime,
delayed,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().Bool(FlagDelayed, false, "Create a delayed vesting account if true")
flags.AddTxFlagsToCmd(cmd)
return cmd
}