diff --git a/simapp/app.go b/simapp/app.go index a85cb4a6d5a5..7a445888aa1c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -275,7 +275,7 @@ func NewSimApp( stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), ) - app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter()) + app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter(), app.AccountKeeper) // register the proposal types govRouter := govtypes.NewRouter() diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 6273dd198fea..b7178535fd1a 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -14,21 +14,24 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/authz" ) type Keeper struct { - storeKey sdk.StoreKey - cdc codec.BinaryCodec - router *baseapp.MsgServiceRouter + storeKey sdk.StoreKey + cdc codec.BinaryCodec + router *baseapp.MsgServiceRouter + authKeeper authkeeper.AccountKeeper } // NewKeeper constructs a message authorization Keeper -func NewKeeper(storeKey sdk.StoreKey, cdc codec.BinaryCodec, router *baseapp.MsgServiceRouter) Keeper { +func NewKeeper(storeKey sdk.StoreKey, cdc codec.BinaryCodec, router *baseapp.MsgServiceRouter, ak authkeeper.AccountKeeper) Keeper { return Keeper{ - storeKey: storeKey, - cdc: cdc, - router: router, + storeKey: storeKey, + cdc: cdc, + router: router, + authKeeper: ak, } } diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index 192ac72d22db..86e829862445 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -23,6 +23,13 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra return nil, err } + // create the account if it is not in account state + granteeAcc := k.authKeeper.GetAccount(ctx, grantee) + if granteeAcc == nil { + granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee) + k.authKeeper.SetAccount(ctx, granteeAcc) + } + authorization := msg.GetAuthorization() if authorization == nil { return nil, sdkerrors.ErrUnpackAny.Wrap("Authorization is not present in the msg")