Skip to content

Commit

Permalink
feat: add start time to vesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Aug 16, 2024
1 parent 7799bba commit dedf5f7
Show file tree
Hide file tree
Showing 15 changed files with 712 additions and 561 deletions.
1 change: 1 addition & 0 deletions proto/cosmos/vesting/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ message MsgCreateVestingAccount {
// end of vesting as unix time (in seconds).
int64 end_time = 4;
bool delayed = 5;
int64 start_time = 6;
}

// MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response type.
Expand Down
2 changes: 1 addition & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ done
cd ..

# generate codec/testdata proto code
(cd testutil/testdata; buf generate)
# (cd testutil/testdata; buf generate)

# move proto files to the right places
cp -r github.com/cosmos/cosmos-sdk/* ./
Expand Down
1 change: 1 addition & 0 deletions snapshots/types/snapshot.pb.go

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

16 changes: 8 additions & 8 deletions types/query/pagination.pb.go

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

26 changes: 13 additions & 13 deletions types/tx/service.pb.go

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

1 change: 1 addition & 0 deletions types/tx/signing/signing.pb.go

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

1 change: 1 addition & 0 deletions types/tx/tx.pb.go

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

5 changes: 4 additions & 1 deletion x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// Transaction command flags
const (
FlagDelayed = "delayed"

Check failure on line 20 in x/auth/vesting/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 20 in x/auth/vesting/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
FlagStartTime = "start-time"
)

// GetTxCmd returns vesting module's transaction commands.
Expand Down Expand Up @@ -72,13 +73,15 @@ timestamp.`,
}

delayed, _ := cmd.Flags().GetBool(FlagDelayed)
startTime, _ := cmd.Flags().GetInt64(FlagStartTime)

msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endTime, delayed)
msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, startTime, endTime, delayed)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

cmd.Flags().Int64(FlagStartTime, 0, "Start time of a delayed vesting")
cmd.Flags().Bool(FlagDelayed, false, "Create a delayed vesting account if true")
flags.AddTxFlagsToCmd(cmd)

Expand Down
9 changes: 8 additions & 1 deletion x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
}

startTime := ctx.BlockTime().Unix()
if (msg.StartTime > 0) && (msg.StartTime < startTime) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, " startTime[%d] < now[%d]", msg.StartTime, startTime)
}else if msg.StartTime > 0 {

Check failure on line 58 in x/auth/vesting/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 58 in x/auth/vesting/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
startTime = msg.StartTime
}

baseAccount := authtypes.NewBaseAccountWithAddress(to)
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount)
baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime)
Expand All @@ -60,7 +67,7 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
if msg.Delayed {
vestingAccount = types.NewDelayedVestingAccountRaw(baseVestingAccount)
} else {
vestingAccount = types.NewContinuousVestingAccountRaw(baseVestingAccount, ctx.BlockTime().Unix())
vestingAccount = types.NewContinuousVestingAccountRaw(baseVestingAccount, startTime)
}

ak.SetAccount(ctx, vestingAccount)
Expand Down
7 changes: 6 additions & 1 deletion x/auth/vesting/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ var _ sdk.Msg = &MsgCreatePeriodicVestingAccount{}
// NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount.
//
//nolint:interfacer
func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins, endTime int64, delayed bool) *MsgCreateVestingAccount {
func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins, startTime, endTime int64, delayed bool) *MsgCreateVestingAccount {
return &MsgCreateVestingAccount{
FromAddress: fromAddr.String(),
ToAddress: toAddr.String(),
Amount: amount,
StartTime: startTime,
EndTime: endTime,
Delayed: delayed,
}
Expand Down Expand Up @@ -62,6 +63,10 @@ func (msg MsgCreateVestingAccount) ValidateBasic() error {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid end time")
}

if msg.StartTime > msg.EndTime {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid start time")
}

return nil
}

Expand Down
122 changes: 80 additions & 42 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.

Loading

0 comments on commit dedf5f7

Please sign in to comment.