-
Notifications
You must be signed in to change notification settings - Fork 49
/
tx.go
58 lines (47 loc) · 1.58 KB
/
tx.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
package cli
import (
"bufio"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/certikfoundation/shentu/x/bank/types"
)
const (
FlagUnlocker = "unlocker"
)
// LockedSendTxCmd sends coins to a manual vesting account
// and have them vesting.
func LockedSendTxCmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "locked-send [from_key_or_address] [to_address] [amount]",
Short: "Send coins and have them locked (vesting).",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)
to, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}
coins, err := sdk.ParseCoins(args[2])
if err != nil {
return err
}
unlocker, err := sdk.AccAddressFromBech32(viper.GetString(FlagUnlocker))
if err != nil {
return err
}
msg := types.NewMsgLockedSend(cliCtx.GetFromAddress(), to, unlocker, coins)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
cmd = flags.PostCommands(cmd)[0]
cmd.Flags().String(FlagUnlocker, "", "unlocker when initializing a new manual vesting account")
return cmd
}