-
Notifications
You must be signed in to change notification settings - Fork 70
/
tx.go
174 lines (150 loc) · 5.47 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package cli
import (
"fmt"
"time"
"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"
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/Canto-Network/Canto/v6/x/vesting/types"
)
// Transaction command flags
const (
FlagDelayed = "delayed"
FlagDest = "dest"
FlagLockup = "lockup"
FlagMerge = "merge"
FlagVesting = "vesting"
FlagClawback = "clawback"
FlagFunder = "funder"
)
// NewTxCmd returns a root CLI command handler for certain modules/vesting
// transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Vesting transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(
NewMsgCreateClawbackVestingAccountCmd(),
NewMsgClawbackCmd(),
)
return txCmd
}
// NewMsgCreateClawbackVestingAccountCmd returns a CLI command handler for creating a
// MsgCreateClawbackVestingAccount transaction.
func NewMsgCreateClawbackVestingAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-clawback-vesting-account [to_address]",
Short: "Create a new vesting account funded with an allocation of tokens, subject to clawback.",
Long: `Must provide a lockup periods file (--lockup), a vesting periods file (--vesting), or both.
If both files are given, they must describe schedules for the same total amount.
If one file is omitted, it will default to a schedule that immediately unlocks or vests the entire amount.
The described amount of coins will be transferred from the --from address to the vesting account.
Unvested coins may be "clawed back" by the funder with the clawback command.
Coins may not be transferred out of the account if they are locked or unvested. Only vested coins may be staked.
A periods file is a JSON object describing a sequence of unlocking or vesting events,
with a start time and an array of coins strings and durations relative to the start or previous event.`,
Example: `Sample period file contents:
{ "start_time": 1625204910,
"period": [
{
"coins": "10test",
"length_seconds": 2592000 //30 days
},
{
"coins": "10test",
"length_seconds": 2592000 //30 days
}
]}
`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var (
lockupStart, vestingStart int64
lockupPeriods, vestingPeriods sdkvesting.Periods
)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
toAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
lockupFile, _ := cmd.Flags().GetString(FlagLockup)
vestingFile, _ := cmd.Flags().GetString(FlagVesting)
if lockupFile == "" && vestingFile == "" {
return fmt.Errorf("must specify at least one of %s or %s", FlagLockup, FlagVesting)
}
if lockupFile != "" {
lockupStart, lockupPeriods, err = ReadScheduleFile(lockupFile)
if err != nil {
return err
}
}
if vestingFile != "" {
vestingStart, vestingPeriods, err = ReadScheduleFile(vestingFile)
if err != nil {
return err
}
}
commonStart, _ := types.AlignSchedules(lockupStart, vestingStart, lockupPeriods, vestingPeriods)
merge, _ := cmd.Flags().GetBool(FlagMerge)
msg := types.NewMsgCreateClawbackVestingAccount(clientCtx.GetFromAddress(), toAddr, time.Unix(commonStart, 0), lockupPeriods, vestingPeriods, merge)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().Bool(FlagMerge, false, "Merge new amount and schedule with existing ClawbackVestingAccount, if any")
cmd.Flags().String(FlagLockup, "", "path to file containing unlocking periods")
cmd.Flags().String(FlagVesting, "", "path to file containing vesting periods")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// NewMsgClawbackCmd returns a CLI command handler for creating a
// MsgClawback transaction.
func NewMsgClawbackCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "clawback [address]",
Short: "Transfer unvested amount out of a ClawbackVestingAccount.",
Long: `Must be requested by the original funder address (--from).
May provide a destination address (--dest), otherwise the coins return to the funder.
Delegated or undelegating staking tokens will be transferred in the delegated (undelegating) state.
The recipient is vulnerable to slashing, and must act to unbond the tokens if desired.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
addr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}
var dest sdk.AccAddress
destString, _ := cmd.Flags().GetString(FlagDest)
if destString != "" {
dest, err = sdk.AccAddressFromBech32(destString)
if err != nil {
return fmt.Errorf("bad dest address: %w", err)
}
}
msg := types.NewMsgClawback(clientCtx.GetFromAddress(), addr, dest)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(FlagDest, "", "address of destination (defaults to funder)")
flags.AddTxFlagsToCmd(cmd)
return cmd
}