fix: update vesting message server to handle base accounts correctly (#12190)
This commit is contained in:
@@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Replace https://github.com/cosmos/cosmos-sdk/pull/12190 to use `NewBaseAccountWithAddress` in all vesting account 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.
|
||||
|
||||
@@ -3,14 +3,13 @@ package vesting
|
||||
import (
|
||||
"context"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
)
|
||||
|
||||
@@ -19,10 +18,6 @@ type msgServer struct {
|
||||
types.BankKeeper
|
||||
}
|
||||
|
||||
type baseAccountGetter interface {
|
||||
GetBaseAccount() *authtypes.BaseAccount
|
||||
}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the vesting MsgServer interface,
|
||||
// wrapping the corresponding AccountKeeper and BankKeeper.
|
||||
func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServer {
|
||||
@@ -57,28 +52,18 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
baseAccount := authtypes.NewBaseAccountWithAddress(to)
|
||||
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount)
|
||||
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")
|
||||
@@ -135,16 +120,11 @@ 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)
|
||||
baseAccount := authtypes.NewBaseAccountWithAddress(to)
|
||||
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount)
|
||||
vestingAccount := types.NewPermanentLockedAccount(baseAccount, msg.Amount)
|
||||
|
||||
baseAcc, ok := baseAccountI.(*authtypes.BaseAccount)
|
||||
if !ok {
|
||||
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccountI)
|
||||
}
|
||||
|
||||
var acc authtypes.AccountI = types.NewPermanentLockedAccount(baseAcc, msg.Amount)
|
||||
|
||||
ak.SetAccount(ctx, acc)
|
||||
ak.SetAccount(ctx, vestingAccount)
|
||||
|
||||
defer func() {
|
||||
telemetry.IncrCounter(1, "new", "account")
|
||||
@@ -200,11 +180,11 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type
|
||||
totalCoins = totalCoins.Add(period.Amount...)
|
||||
}
|
||||
|
||||
baseAccount := ak.NewAccountWithAddress(ctx, to)
|
||||
baseAccount := authtypes.NewBaseAccountWithAddress(to)
|
||||
baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount)
|
||||
vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
|
||||
|
||||
acc := types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), msg.StartTime, msg.VestingPeriods)
|
||||
|
||||
ak.SetAccount(ctx, acc)
|
||||
ak.SetAccount(ctx, vestingAccount)
|
||||
|
||||
defer func() {
|
||||
telemetry.IncrCounter(1, "new", "account")
|
||||
|
||||
Reference in New Issue
Block a user