Skip to content

Commit

Permalink
fix: add extra check in vesting (backport cosmos#15373) (cosmos#15383)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
mergify[bot] and julienrbrt authored Mar 14, 2023
1 parent f939979 commit f382e43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Improvements

* (simapp) [#15305](https://github.com/cosmos/cosmos-sdk/pull/15305) Add `AppStateFnWithExtendedCb` with callback function to extend rawState and `AppStateRandomizedFnWithState` with extra genesisState argument which is the genesis state of the app.

### Bug Fixes

* (x/auth/vesting) [#15383](https://github.com/cosmos/cosmos-sdk/pull/15383) Add extra checks when creating a periodic vesting account.

## [v0.46.11](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.11) - 2022-03-03

### Improvements
Expand Down
14 changes: 7 additions & 7 deletions x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
}
}()

err = bk.SendCoins(ctx, from, to, msg.Amount)
if err != nil {
if err = bk.SendCoins(ctx, from, to, msg.Amount); err != nil {
return nil, err
}

Expand Down Expand Up @@ -140,8 +139,7 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type
}
}()

err = bk.SendCoins(ctx, from, to, msg.Amount)
if err != nil {
if err = bk.SendCoins(ctx, from, to, msg.Amount); err != nil {
return nil, err
}

Expand Down Expand Up @@ -175,11 +173,14 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
}

var totalCoins sdk.Coins

for _, period := range msg.VestingPeriods {
totalCoins = totalCoins.Add(period.Amount...)
}

if err := bk.IsSendEnabledCoins(ctx, totalCoins...); err != nil {
return nil, err
}

baseAccount := authtypes.NewBaseAccountWithAddress(to)
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount)
vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
Expand All @@ -200,8 +201,7 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
}
}()

err = bk.SendCoins(ctx, from, to, totalCoins)
if err != nil {
if err = bk.SendCoins(ctx, from, to, totalCoins); err != nil {
return nil, err
}

Expand Down

0 comments on commit f382e43

Please sign in to comment.