github.com/Finschia/finschia-sdk@v0.49.1/x/auth/vesting/client/cli/tx.go (about) 1 package cli 2 3 import ( 4 "strconv" 5 6 "github.com/spf13/cobra" 7 8 "github.com/Finschia/finschia-sdk/client" 9 "github.com/Finschia/finschia-sdk/client/flags" 10 "github.com/Finschia/finschia-sdk/client/tx" 11 sdk "github.com/Finschia/finschia-sdk/types" 12 "github.com/Finschia/finschia-sdk/x/auth/vesting/types" 13 ) 14 15 // Transaction command flags 16 const ( 17 FlagDelayed = "delayed" 18 ) 19 20 // GetTxCmd returns vesting module's transaction commands. 21 func GetTxCmd() *cobra.Command { 22 txCmd := &cobra.Command{ 23 Use: types.ModuleName, 24 Short: "Vesting transaction subcommands", 25 DisableFlagParsing: true, 26 SuggestionsMinimumDistance: 2, 27 RunE: client.ValidateCmd, 28 } 29 30 txCmd.AddCommand( 31 NewMsgCreateVestingAccountCmd(), 32 ) 33 34 return txCmd 35 } 36 37 // NewMsgCreateVestingAccountCmd returns a CLI command handler for creating a 38 // MsgCreateVestingAccount transaction. 39 func NewMsgCreateVestingAccountCmd() *cobra.Command { 40 cmd := &cobra.Command{ 41 Use: "create-vesting-account [to_address] [amount] [end_time]", 42 Short: "Create a new vesting account funded with an allocation of tokens.", 43 Long: `Create a new vesting account funded with an allocation of tokens. The 44 account can either be a delayed or continuous vesting account, which is determined 45 by the '--delayed' flag. All vesting accouts created will have their start time 46 set by the committed block's time. The end_time must be provided as a UNIX epoch 47 timestamp.`, 48 Args: cobra.ExactArgs(3), 49 RunE: func(cmd *cobra.Command, args []string) error { 50 clientCtx, err := client.GetClientTxContext(cmd) 51 if err != nil { 52 return err 53 } 54 toAddr, err := sdk.AccAddressFromBech32(args[0]) 55 if err != nil { 56 return err 57 } 58 59 amount, err := sdk.ParseCoinsNormalized(args[1]) 60 if err != nil { 61 return err 62 } 63 64 endTime, err := strconv.ParseInt(args[2], 10, 64) 65 if err != nil { 66 return err 67 } 68 69 delayed, _ := cmd.Flags().GetBool(FlagDelayed) 70 71 msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endTime, delayed) 72 73 return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) 74 }, 75 } 76 77 cmd.Flags().Bool(FlagDelayed, false, "Create a delayed vesting account if true") 78 flags.AddTxFlagsToCmd(cmd) 79 80 return cmd 81 }