Skip to content

Commit a39be7b

Browse files
authored
fix: add base account getter (#12154)
1 parent 544afb6 commit a39be7b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6060
* (cli) [#12095](https://github.com/cosmos/cosmos-sdk/pull/12095) Fix running a tx with --dry-run returns an error
6161
* (x/auth) [#12108](https://github.com/cosmos/cosmos-sdk/pull/12108) Fix GetBlockWithTxs error when querying block with 0 tx
6262
* (genutil) [#12140](https://github.com/cosmos/cosmos-sdk/pull/12140) Fix staking's genesis JSON migrate in the `simd migrate v0.46` CLI command.
63+
* (types) [#12154](https://github.com/cosmos/cosmos-sdk/pull/12154) Add `baseAccountGetter` to avoid invalid account error when create vesting account.
6364

6465
## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23
6566

x/auth/vesting/msg_server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ type msgServer struct {
1919
types.BankKeeper
2020
}
2121

22+
type baseAccountGetter interface {
23+
GetBaseAccount() *authtypes.BaseAccount
24+
}
25+
2226
// NewMsgServerImpl returns an implementation of the vesting MsgServer interface,
2327
// wrapping the corresponding AccountKeeper and BankKeeper.
2428
func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServer {
@@ -53,12 +57,18 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
5357
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress)
5458
}
5559

56-
baseAccount := ak.NewAccountWithAddress(ctx, to)
57-
if _, ok := baseAccount.(*authtypes.BaseAccount); !ok {
60+
account := ak.NewAccountWithAddress(ctx, to)
61+
baseAccount, ok := account.(*authtypes.BaseAccount)
62+
if !ok {
63+
if getter, ok := account.(baseAccountGetter); ok {
64+
baseAccount = getter.GetBaseAccount()
65+
}
66+
}
67+
if baseAccount == nil {
5868
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount)
5969
}
6070

61-
baseVestingAccount := types.NewBaseVestingAccount(baseAccount.(*authtypes.BaseAccount), msg.Amount.Sort(), msg.EndTime)
71+
baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime)
6272

6373
var acc authtypes.AccountI
6474

0 commit comments

Comments
 (0)