From a39be7b78fa59422bfdd3d8ce398356152914a40 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Mon, 6 Jun 2022 23:37:44 +0800 Subject: [PATCH] fix: add base account getter (#12154) --- CHANGELOG.md | 1 + x/auth/vesting/msg_server.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd402996af..67e790c454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [#12095](https://github.com/cosmos/cosmos-sdk/pull/12095) Fix running a tx with --dry-run returns an error * (x/auth) [#12108](https://github.com/cosmos/cosmos-sdk/pull/12108) Fix GetBlockWithTxs error when querying block with 0 tx * (genutil) [#12140](https://github.com/cosmos/cosmos-sdk/pull/12140) Fix staking's genesis JSON migrate in the `simd migrate v0.46` CLI command. +* (types) [#12154](https://github.com/cosmos/cosmos-sdk/pull/12154) Add `baseAccountGetter` to avoid invalid account error when create vesting account. ## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23 diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index 90377947a0..e3fd521a62 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -19,6 +19,10 @@ 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 { @@ -53,12 +57,18 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress) } - baseAccount := ak.NewAccountWithAddress(ctx, to) - if _, ok := baseAccount.(*authtypes.BaseAccount); !ok { + 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) } - baseVestingAccount := types.NewBaseVestingAccount(baseAccount.(*authtypes.BaseAccount), msg.Amount.Sort(), msg.EndTime) + baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime) var acc authtypes.AccountI