Skip to content

Commit

Permalink
Merge pull request #66 from agoric-labs/zaki-add-starting-vesting-msg
Browse files Browse the repository at this point in the history
Add support start time to periodic vesting messages
  • Loading branch information
zmanian authored Jun 27, 2021
2 parents 780f61c + 8b0a8c2 commit 98e8de7
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 47 deletions.
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8148,6 +8148,7 @@ account.
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | |
| `to_address` | [string](#string) | | |
| `start_time` | [int64](#int64) | | |
| `vesting_periods` | [Period](#cosmos.vesting.v1beta1.Period) | repeated | |


Expand Down
3 changes: 2 additions & 1 deletion proto/cosmos/vesting/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ message MsgCreatePeriodicVestingAccount {

string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""];
string to_address = 2 [(gogoproto.moretags) = "yaml:\"to_address\""];
repeated Period vesting_periods = 3 [(gogoproto.nullable) = false];
int64 start_time = 3 [(gogoproto.moretags) = "yaml:\"start_time\""];
repeated Period vesting_periods = 4 [(gogoproto.nullable) = false];
}
16 changes: 11 additions & 5 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type InputPeriod struct {
// MsgCreateVestingAccount transaction.
func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-periodic-vesting-account [to_address] [periods_json_file]",
Use: "create-periodic-vesting-account [start_time_unix] [to_address] [periods_json_file]",
Short: "Create a new vesting account funded with an allocation of tokens.",
Long: `A sequence of coins and period length in seconds. Periods are sequential, in that the duration of of a period only starts at the end of the previous period. The duration of the first period starts upon account creation. For instance, the following periods.json file shows 20 "test" coins vesting 30 days apart from each other.
Where periods.json contains:
Expand All @@ -117,19 +117,25 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
if err != nil {
return err
}
toAddr, err := sdk.AccAddressFromBech32(args[0])

startTime, err := strconv.ParseInt(args[0], 10, 64)

if err != nil {
return err
}
toAddr, err := sdk.AccAddressFromBech32(args[1])
if err != nil {
return err
}

contents, err := ioutil.ReadFile(args[1])
contents, err := ioutil.ReadFile(args[2])
if err != nil {
return err
}

var inputPeriods []InputPeriod

err = json.Unmarshal(contents, inputPeriods)
err = json.Unmarshal(contents, &inputPeriods)
if err != nil {
return err
}
Expand All @@ -150,7 +156,7 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
periods = append(periods, period)
}

msg := types.NewMsgCreatePeriodicVestingAccount(clientCtx.GetFromAddress(), toAddr, periods)
msg := types.NewMsgCreatePeriodicVestingAccount(clientCtx.GetFromAddress(), toAddr, startTime, periods)
if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
if acc := ak.GetAccount(ctx, to); acc != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
}

var totalCoins sdk.Coins

for _, period := range msg.VestingPeriods {
Expand All @@ -129,7 +130,7 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type

baseAccount := ak.NewAccountWithAddress(ctx, to)

types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), ctx.BlockTime().Unix(), msg.VestingPeriods)
types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)

err = bk.SendCoins(ctx, from, to, totalCoins)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion x/auth/vesting/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ func (msg MsgCreateVestingAccount) GetSigners() []sdk.AccAddress {

// NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount.
//nolint:interfacer
func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, periods []Period) *MsgCreatePeriodicVestingAccount {
func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTime int64, periods []Period) *MsgCreatePeriodicVestingAccount {
return &MsgCreatePeriodicVestingAccount{
FromAddress: fromAddr.String(),
ToAddress: toAddr.String(),
StartTime: startTime,
VestingPeriods: periods,
}
}
Expand Down
103 changes: 70 additions & 33 deletions x/auth/vesting/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions x/slashing/types/slashing.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98e8de7

Please sign in to comment.