Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update vesting message server to handle base accounts correctly #12190

Merged
merged 13 commits into from
Jun 14, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Extend https://github.com/cosmos/cosmos-sdk/pull/12190 to apply to all vesting message handlers.
* (linting) [#12135](https://github.com/cosmos/cosmos-sdk/pull/12135/) Fix variable naming issues per enabled linters. Run gofumpt to ensure easy reviews of ongoing linting work.
* (linting) [#12132](https://github.com/cosmos/cosmos-sdk/pull/12132) Change sdk.Int to math.Int, run `gofumpt -w -l .`, and `golangci-lint run ./... --fix`
* (cli) [#12127](https://github.com/cosmos/cosmos-sdk/pull/12127) Fix the CLI not always taking into account `--fee-payer` and `--fee-granter` flags.
Expand Down
42 changes: 26 additions & 16 deletions x/auth/vesting/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre

baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime)

var acc authtypes.AccountI

var vestingAccount authtypes.AccountI
if msg.Delayed {
acc = types.NewDelayedVestingAccountRaw(baseVestingAccount)
vestingAccount = types.NewDelayedVestingAccountRaw(baseVestingAccount)
} else {
acc = types.NewContinuousVestingAccountRaw(baseVestingAccount, ctx.BlockTime().Unix())
vestingAccount = types.NewContinuousVestingAccountRaw(baseVestingAccount, ctx.BlockTime().Unix())
}

ak.SetAccount(ctx, acc)
ak.SetAccount(ctx, vestingAccount)

defer func() {
telemetry.IncrCounter(1, "new", "account")
Expand Down Expand Up @@ -135,16 +134,19 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
}

baseAccountI := ak.NewAccountWithAddress(ctx, to)

baseAcc, ok := baseAccountI.(*authtypes.BaseAccount)
account := ak.NewAccountWithAddress(ctx, to)
baseAccount, ok := account.(*authtypes.BaseAccount)
if !ok {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccountI)
if getter, ok := account.(baseAccountGetter); ok {
baseAccount = getter.GetBaseAccount()
}
}
if baseAccount == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount)
}
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

var acc authtypes.AccountI = types.NewPermanentLockedAccount(baseAcc, msg.Amount)

ak.SetAccount(ctx, acc)
vestingAccount := types.NewPermanentLockedAccount(baseAccount, msg.Amount)
ak.SetAccount(ctx, vestingAccount)

defer func() {
telemetry.IncrCounter(1, "new", "account")
Expand Down Expand Up @@ -200,11 +202,19 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
totalCoins = totalCoins.Add(period.Amount...)
}

baseAccount := ak.NewAccountWithAddress(ctx, to)

acc := types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
account := ak.NewAccountWithAddress(ctx, to)
baseAccount, ok := account.(*authtypes.BaseAccount)
if !ok {
if getter, ok := account.(baseAccountGetter); ok {
baseAccount = getter.GetBaseAccount()
}
}
if baseAccount == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount)
}
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

ak.SetAccount(ctx, acc)
vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
ak.SetAccount(ctx, vestingAccount)

defer func() {
telemetry.IncrCounter(1, "new", "account")
Expand Down