diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bc650a429c..b45d148567ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ older clients. ### API Breaking Changes +* (x/auth) [\#6029](https://github.com/cosmos/cosmos-sdk/pull/6029) Module accounts have been moved from `x/supply` to `x/auth`. * (x/supply) [\#6010](https://github.com/cosmos/cosmos-sdk/pull/6010) All `x/supply` types and APIs have been moved to `x/bank`. * (baseapp) [\#5865](https://github.com/cosmos/cosmos-sdk/pull/5865) The `SimulationResponse` returned from tx simulation is now JSON encoded instead of Amino binary. * [\#5719](https://github.com/cosmos/cosmos-sdk/pull/5719) Bump Go requirement to 1.14+ diff --git a/codec/std/codec.pb.go b/codec/std/codec.pb.go index b07fdd9cb8de..8b9d4b4d4cd8 100644 --- a/codec/std/codec.pb.go +++ b/codec/std/codec.pb.go @@ -106,7 +106,7 @@ type Account_PeriodicVestingAccount struct { PeriodicVestingAccount *types1.PeriodicVestingAccount `protobuf:"bytes,4,opt,name=periodic_vesting_account,json=periodicVestingAccount,proto3,oneof" json:"periodic_vesting_account,omitempty"` } type Account_ModuleAccount struct { - ModuleAccount *types2.ModuleAccount `protobuf:"bytes,5,opt,name=module_account,json=moduleAccount,proto3,oneof" json:"module_account,omitempty"` + ModuleAccount *types.ModuleAccount `protobuf:"bytes,5,opt,name=module_account,json=moduleAccount,proto3,oneof" json:"module_account,omitempty"` } func (*Account_BaseAccount) isAccount_Sum() {} @@ -150,7 +150,7 @@ func (m *Account) GetPeriodicVestingAccount() *types1.PeriodicVestingAccount { return nil } -func (m *Account) GetModuleAccount() *types2.ModuleAccount { +func (m *Account) GetModuleAccount() *types.ModuleAccount { if x, ok := m.GetSum().(*Account_ModuleAccount); ok { return x.ModuleAccount } @@ -1191,116 +1191,116 @@ func init() { proto.RegisterFile("codec/std/codec.proto", fileDescriptor_daf09dc var fileDescriptor_daf09dc2dfa19bb4 = []byte{ // 1753 bytes of a gzipped FileDescriptorProto - 0x1f, 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, 0xa3, + 0xb6, 0x2e, 0x25, 0x3c, 0x0a, 0x58, 0x28, 0xb0, 0xdb, 0xd2, 0xd0, 0xee, 0x65, 0xb0, 0xc0, 0x23, + 0xda, 0xfc, 0xad, 0x09, 0x16, 0xf7, 0xa2, 0x20, 0x18, 0x8c, 0xe1, 0xdb, 0x60, 0x91, 0xab, 0x27, + 0x9d, 0x35, 0x37, 0xf2, 0x92, 0x64, 0xbd, 0x49, 0x49, 0xb1, 0x77, 0xcf, 0xb0, 0xb4, 0x77, 0xe7, + 0xdd, 0xff, 0x7e, 0xdc, 0x30, 0x2f, 0x22, 0x44, 0x55, 0x6c, 0x2a, 0x24, 0xe6, 0xd9, 0x49, 0x84, + 0xfc, 0xd9, 0x04, 0x95, 0xc7, 0xba, 0xf4, 0xe0, 0xfb, 0xa0, 0x8a, 0x3f, 0x8c, 0xc8, 0x90, 0x39, + 0x48, 0x16, 0xaa, 0x16, 0x74, 0x3b, 0x2f, 0x28, 0x29, 0x54, 0x29, 0xea, 0x71, 0xc6, 0xbb, 0x67, + 0x58, 0x39, 0x74, 0xe7, 0x91, 0x16, 0xf8, 0xe0, 0x1c, 0x7d, 0x69, 0xe5, 0xa7, 0x1a, 0x13, 0x41, + 0x89, 0xc8, 0xbf, 0x9b, 0x60, 0x6d, 0x97, 0x7b, 0x7b, 0x51, 0x9f, 0x12, 0x91, 0xaa, 0xdd, 0x05, + 0x25, 0x59, 0x3b, 0x5a, 0x65, 0xfb, 0x6c, 0x95, 0x33, 0x50, 0x59, 0x81, 0xdd, 0xca, 0xa7, 0x27, + 0x0d, 0xe3, 0xf9, 0x49, 0xc3, 0xb4, 0x14, 0x0d, 0x7c, 0x17, 0x54, 0x12, 0x90, 0xae, 0xb4, 0x5c, + 0xfd, 0x66, 0xcf, 0xea, 0x54, 0xa0, 0x95, 0x42, 0x3a, 0x95, 0xdf, 0x7d, 0xdc, 0x30, 0xe4, 0x1b, + 0x37, 0xff, 0x92, 0x55, 0xfb, 0x44, 0x9f, 0x2b, 0xb0, 0x97, 0x53, 0x7b, 0x27, 0xaf, 0xd6, 0x63, + 0xc3, 0x9c, 0xd0, 0x04, 0x55, 0x28, 0xb4, 0x03, 0xca, 0xb2, 0x90, 0x71, 0x7a, 0x22, 0xdc, 0x3c, + 0x53, 0xe7, 0x66, 0xec, 0x67, 0x25, 0x80, 0x8c, 0xca, 0x3f, 0x98, 0xa0, 0x92, 0x8a, 0xfb, 0x41, + 0x4e, 0xdc, 0xad, 0x42, 0x71, 0x73, 0x35, 0x3d, 0xfc, 0xc2, 0x9a, 0xba, 0x25, 0x49, 0x31, 0x51, + 0x56, 0x52, 0xaa, 0xfe, 0x54, 0x02, 0x65, 0xed, 0x00, 0xdf, 0x01, 0x25, 0x81, 0x47, 0x62, 0xae, + 0xa8, 0xa7, 0x78, 0x94, 0x2e, 0x56, 0xcf, 0xb0, 0x14, 0x00, 0x7e, 0x00, 0x56, 0xd5, 0xd9, 0x8e, + 0x05, 0x0e, 0x6d, 0xe7, 0x10, 0xf9, 0x5e, 0xb2, 0xa3, 0x53, 0x49, 0x12, 0x77, 0x00, 0xf5, 0x72, + 0x89, 0xff, 0xa6, 0x72, 0xcf, 0x50, 0x5e, 0x0d, 0xf2, 0x26, 0xf8, 0x73, 0xb0, 0xca, 0xd9, 0x81, + 0x38, 0x46, 0x21, 0xb6, 0x75, 0x77, 0xd0, 0x87, 0xe4, 0x9b, 0x79, 0x76, 0x6d, 0x54, 0xc5, 0xab, + 0x01, 0xcf, 0xe2, 0xa9, 0x2c, 0x3d, 0xcf, 0x9b, 0x60, 0x00, 0xd6, 0x1d, 0xe4, 0x3b, 0x78, 0x60, + 0xcf, 0x44, 0x29, 0x15, 0x9d, 0xff, 0x99, 0x28, 0x9b, 0x0a, 0x77, 0x76, 0xac, 0xeb, 0x4e, 0x91, + 0x03, 0x1c, 0x80, 0x6b, 0x0e, 0xa3, 0x34, 0xf2, 0x89, 0x18, 0xdb, 0x01, 0x63, 0x03, 0x9b, 0x07, + 0x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xff, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x02, 0x85, 0x89, 0xbb, 0xba, 0x13, 0x00, 0x00, } func (this *Supply) Equal(that interface{}) bool { @@ -1711,7 +1711,7 @@ func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_export case *types1.PeriodicVestingAccount: this.Sum = &Account_PeriodicVestingAccount{vt} return nil - case *types2.ModuleAccount: + case *types.ModuleAccount: this.Sum = &Account_ModuleAccount{vt} return nil } @@ -3943,7 +3943,7 @@ func (m *Account) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - v := &types2.ModuleAccount{} + v := &types.ModuleAccount{} if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/codec/std/codec.proto b/codec/std/codec.proto index e0903c354835..adf1e023bc0d 100644 --- a/codec/std/codec.proto +++ b/codec/std/codec.proto @@ -28,7 +28,7 @@ message Account { cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2; cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3; cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4; - cosmos_sdk.x.bank.v1.ModuleAccount module_account = 5; + cosmos_sdk.x.auth.v1.ModuleAccount module_account = 5; } } diff --git a/simapp/app.go b/simapp/app.go index ea8306a3dde3..958ba627af87 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -75,11 +75,11 @@ var ( maccPerms = map[string][]string{ auth.FeeCollectorName: nil, distr.ModuleName: nil, - mint.ModuleName: {bank.Minter}, - staking.BondedPoolName: {bank.Burner, bank.Staking}, - staking.NotBondedPoolName: {bank.Burner, bank.Staking}, - gov.ModuleName: {bank.Burner}, - transfer.GetModuleAccountName(): {bank.Minter, bank.Burner}, + mint.ModuleName: {auth.Minter}, + staking.BondedPoolName: {auth.Burner, auth.Staking}, + staking.NotBondedPoolName: {auth.Burner, auth.Staking}, + gov.ModuleName: {auth.Burner}, + transfer.GetModuleAccountName(): {auth.Minter, auth.Burner}, } // module accounts that are allowed to receive tokens @@ -188,21 +188,21 @@ func NewSimApp( // add keepers app.AccountKeeper = auth.NewAccountKeeper( - appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, + appCodec, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, maccPerms, ) app.BankKeeper = bank.NewBaseKeeper( - appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), maccPerms, + appCodec, keys[bank.StoreKey], app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(), ) stakingKeeper := staking.NewKeeper( - appCodec, keys[staking.StoreKey], app.BankKeeper, app.subspaces[staking.ModuleName], + appCodec, keys[staking.StoreKey], app.AccountKeeper, app.BankKeeper, app.subspaces[staking.ModuleName], ) app.MintKeeper = mint.NewKeeper( appCodec, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper, - app.BankKeeper, auth.FeeCollectorName, + app.AccountKeeper, app.BankKeeper, auth.FeeCollectorName, ) app.DistrKeeper = distr.NewKeeper( - appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.BankKeeper, &stakingKeeper, - auth.FeeCollectorName, app.ModuleAccountAddrs(), + appCodec, keys[distr.StoreKey], app.subspaces[distr.ModuleName], app.AccountKeeper, app.BankKeeper, + &stakingKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) app.SlashingKeeper = slashing.NewKeeper( appCodec, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName], @@ -219,7 +219,7 @@ func NewSimApp( AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)). AddRoute(upgrade.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) app.GovKeeper = gov.NewKeeper( - appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.BankKeeper, + appCodec, keys[gov.StoreKey], app.subspaces[gov.ModuleName], app.AccountKeeper, app.BankKeeper, &stakingKeeper, govRouter, ) @@ -238,7 +238,7 @@ func NewSimApp( app.TransferKeeper = transfer.NewKeeper( app.cdc, keys[transfer.StoreKey], app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, - app.BankKeeper, scopedTransferKeeper, + app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, ) transferModule := transfer.NewAppModule(app.TransferKeeper) @@ -261,12 +261,12 @@ func NewSimApp( // must be passed by reference here. app.mm = module.NewManager( genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx), - auth.NewAppModule(app.AccountKeeper, app.BankKeeper), + auth.NewAppModule(app.AccountKeeper), bank.NewAppModule(app.BankKeeper, app.AccountKeeper), capability.NewAppModule(*app.CapabilityKeeper), crisis.NewAppModule(&app.CrisisKeeper), gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(app.MintKeeper, app.BankKeeper), + mint.NewAppModule(app.MintKeeper, app.AccountKeeper), slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper), @@ -302,10 +302,10 @@ func NewSimApp( // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions app.sm = module.NewSimulationManager( - auth.NewAppModule(app.AccountKeeper, app.BankKeeper), + auth.NewAppModule(app.AccountKeeper), bank.NewAppModule(app.BankKeeper, app.AccountKeeper), gov.NewAppModule(app.GovKeeper, app.AccountKeeper, app.BankKeeper), - mint.NewAppModule(app.MintKeeper, app.BankKeeper), + mint.NewAppModule(app.MintKeeper, app.AccountKeeper), staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.BankKeeper), distr.NewAppModule(app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), @@ -376,7 +376,7 @@ func (app *SimApp) LoadHeight(height int64) error { func (app *SimApp) ModuleAccountAddrs() map[string]bool { modAccAddrs := make(map[string]bool) for acc := range maccPerms { - modAccAddrs[bank.NewModuleAddress(acc).String()] = true + modAccAddrs[auth.NewModuleAddress(acc).String()] = true } return modAccAddrs @@ -386,7 +386,7 @@ func (app *SimApp) ModuleAccountAddrs() map[string]bool { func (app *SimApp) BlacklistedAccAddrs() map[string]bool { blacklistedAddrs := make(map[string]bool) for acc := range maccPerms { - blacklistedAddrs[bank.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc] + blacklistedAddrs[auth.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc] } return blacklistedAddrs diff --git a/simapp/app_test.go b/simapp/app_test.go index 688f85794b59..3fcf897de880 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -42,7 +42,7 @@ func TestBlackListedAddrs(t *testing.T) { app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) for acc := range maccPerms { - require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlacklistedAddr(app.BankKeeper.GetModuleAddress(acc))) + require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlacklistedAddr(app.AccountKeeper.GetModuleAddress(acc))) } } diff --git a/simapp/genesis_account.go b/simapp/genesis_account.go index 3522516cac0d..1725b6982fd8 100644 --- a/simapp/genesis_account.go +++ b/simapp/genesis_account.go @@ -4,9 +4,9 @@ import ( "errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank" ) var _ authexported.GenesisAccount = (*SimGenesisAccount)(nil) @@ -37,7 +37,7 @@ func (sga SimGenesisAccount) Validate() error { } if sga.ModuleName != "" { - ma := bank.ModuleAccount{ + ma := auth.ModuleAccount{ BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions, } if err := ma.Validate(); err != nil { diff --git a/x/auth/alias.go b/x/auth/alias.go index 1ff692c74ce3..927fb5a550af 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -23,6 +23,9 @@ const ( QueryAccount = types.QueryAccount QueryParams = types.QueryParams MaxGasWanted = types.MaxGasWanted + Minter = types.Minter + Burner = types.Burner + Staking = types.Staking ) var ( @@ -60,6 +63,9 @@ var ( ValidateGenAccounts = types.ValidateGenAccounts GetGenesisStateFromAppState = types.GetGenesisStateFromAppState NewStdSignature = types.NewStdSignature + NewModuleAddress = types.NewModuleAddress + NewEmptyModuleAccount = types.NewEmptyModuleAccount + NewModuleAccount = types.NewModuleAccount // variable aliases ModuleCdc = types.ModuleCdc @@ -89,4 +95,5 @@ type ( TxBuilder = types.TxBuilder GenesisAccountIterator = types.GenesisAccountIterator Codec = types.Codec + ModuleAccount = types.ModuleAccount ) diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 2bfc3cadbe10..c807be803a06 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -359,7 +359,7 @@ func TestAnteHandlerFees(t *testing.T) { app.BankKeeper.SetBalances(ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("atom", 149))) checkInvalidTx(t, anteHandler, ctx, tx, false, sdkerrors.ErrInsufficientFunds) - modAcc := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName) + modAcc := app.AccountKeeper.GetModuleAccount(ctx, types.FeeCollectorName) require.True(t, app.BankKeeper.GetAllBalances(ctx, modAcc.GetAddress()).Empty()) require.True(sdk.IntEq(t, app.BankKeeper.GetAllBalances(ctx, addr1).AmountOf("atom"), sdk.NewInt(149))) diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 7d9a5f23d813..d15c89332653 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -89,7 +89,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") } - if addr := dfd.bankKeeper.GetModuleAddress(types.FeeCollectorName); addr == nil { + if addr := dfd.ak.GetModuleAddress(types.FeeCollectorName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.FeeCollectorName)) } diff --git a/x/auth/exported/exported.go b/x/auth/exported/exported.go index 7b97e8df1791..1974ff9ae4dc 100644 --- a/x/auth/exported/exported.go +++ b/x/auth/exported/exported.go @@ -29,6 +29,16 @@ type Account interface { String() string } +// ModuleAccountI defines an account interface for modules that hold tokens in +// an escrow. +type ModuleAccountI interface { + Account + + GetName() string + GetPermissions() []string + HasPermission(string) bool +} + // GenesisAccounts defines a slice of GenesisAccount objects type GenesisAccounts []GenesisAccount diff --git a/x/auth/genesis.go b/x/auth/genesis.go index 0801e98fd983..606e4f410d5c 100644 --- a/x/auth/genesis.go +++ b/x/auth/genesis.go @@ -3,14 +3,13 @@ package auth import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/auth/types" ) // InitGenesis - Init store state from genesis data // // CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through // a genesis port script to the new fee collector account -func InitGenesis(ctx sdk.Context, ak AccountKeeper, bk types.BankKeeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, ak AccountKeeper, data GenesisState) { ak.SetParams(ctx, data.Params) data.Accounts = SanitizeGenesisAccounts(data.Accounts) @@ -19,7 +18,7 @@ func InitGenesis(ctx sdk.Context, ak AccountKeeper, bk types.BankKeeper, data Ge ak.SetAccount(ctx, acc) } - bk.GetModuleAccount(ctx, FeeCollectorName) + ak.GetModuleAccount(ctx, FeeCollectorName) } // ExportGenesis returns a GenesisState for a given context and keeper diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 3a0c7d5a921c..2db0dec2e464 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -20,6 +20,7 @@ type AccountKeeper struct { key sdk.StoreKey cdc types.Codec paramSubspace paramtypes.Subspace + permAddrs map[string]types.PermissionsForAddress // The prototypical Account constructor. proto func() exported.Account @@ -29,6 +30,7 @@ type AccountKeeper struct { // (binary) encode and decode concrete sdk.Accounts. func NewAccountKeeper( cdc types.Codec, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() exported.Account, + maccPerms map[string][]string, ) AccountKeeper { // set KeyTable if it has not already been set @@ -36,11 +38,17 @@ func NewAccountKeeper( paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) } + permAddrs := make(map[string]types.PermissionsForAddress) + for name, perms := range maccPerms { + permAddrs[name] = types.NewPermissionsForAddress(name, perms) + } + return AccountKeeper{ key: key, proto: proto, cdc: cdc, paramSubspace: paramstore, + permAddrs: permAddrs, } } @@ -96,6 +104,76 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { return accNumber } +// ValidatePermissions validates that the module account has been granted +// permissions within its set of allowed permissions. +func (ak AccountKeeper) ValidatePermissions(macc exported.ModuleAccountI) error { + permAddr := ak.permAddrs[macc.GetName()] + for _, perm := range macc.GetPermissions() { + if !permAddr.HasPermission(perm) { + return fmt.Errorf("invalid module permission %s", perm) + } + } + + return nil +} + +// GetModuleAddress returns an address based on the module name +func (ak AccountKeeper) GetModuleAddress(moduleName string) sdk.AccAddress { + permAddr, ok := ak.permAddrs[moduleName] + if !ok { + return nil + } + + return permAddr.GetAddress() +} + +// GetModuleAddressAndPermissions returns an address and permissions based on the module name +func (ak AccountKeeper) GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) { + permAddr, ok := ak.permAddrs[moduleName] + if !ok { + return addr, permissions + } + + return permAddr.GetAddress(), permAddr.GetPermissions() +} + +// GetModuleAccountAndPermissions gets the module account from the auth account store and its +// registered permissions +func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) { + addr, perms := ak.GetModuleAddressAndPermissions(moduleName) + if addr == nil { + return nil, []string{} + } + + acc := ak.GetAccount(ctx, addr) + if acc != nil { + macc, ok := acc.(exported.ModuleAccountI) + if !ok { + panic("account is not a module account") + } + return macc, perms + } + + // create a new module account + macc := types.NewEmptyModuleAccount(moduleName, perms...) + maccI := (ak.NewAccount(ctx, macc)).(exported.ModuleAccountI) // set the account number + ak.SetModuleAccount(ctx, maccI) + + return maccI, perms +} + +// GetModuleAccount gets the module account from the auth account store, if the account does not +// exist in the AccountKeeper, then it is created. +func (ak AccountKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI { + acc, _ := ak.GetModuleAccountAndPermissions(ctx, moduleName) + return acc +} + +// SetModuleAccount sets the module account to the auth account store +func (ak AccountKeeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) { //nolint:interfacer + ak.SetAccount(ctx, macc) +} + func (ak AccountKeeper) decodeAccount(bz []byte) exported.Account { acc, err := ak.cdc.UnmarshalAccount(bz) if err != nil { diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 73e1a9ef6e76..814d0f5107be 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -5,10 +5,24 @@ import ( "github.com/stretchr/testify/require" + codecstd "github.com/cosmos/cosmos-sdk/codec/std" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/types" ) +const ( + holder = "holder" + multiPerm = "multiple permissions account" + randomPerm = "random permission" +) + +var ( + multiPermAcc = auth.NewEmptyModuleAccount(multiPerm, auth.Burner, auth.Minter, auth.Staking) + randomPermAcc = auth.NewEmptyModuleAccount(randomPerm, "random") +) + func TestAccountMapperGetSet(t *testing.T) { app, ctx := createTestApp(true) addr := sdk.AccAddress([]byte("some-address")) @@ -81,3 +95,32 @@ func TestGetSetParams(t *testing.T) { actualParams := app.AccountKeeper.GetParams(ctx) require.Equal(t, params, actualParams) } + +func TestSupply_ValidatePermissions(t *testing.T) { + app, _ := createTestApp(true) + + // add module accounts to supply keeper + maccPerms := simapp.GetMaccPerms() + maccPerms[holder] = nil + maccPerms[types.Burner] = []string{types.Burner} + maccPerms[auth.Minter] = []string{types.Minter} + maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[randomPerm] = []string{"random"} + + appCodec := codecstd.NewAppCodec(app.Codec()) + keeper := auth.NewAccountKeeper( + appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), + types.ProtoBaseAccount, maccPerms, + ) + + err := keeper.ValidatePermissions(multiPermAcc) + require.NoError(t, err) + + err = keeper.ValidatePermissions(randomPermAcc) + require.NoError(t, err) + + // unregistered permissions + otherAcc := types.NewEmptyModuleAccount("other", "other") + err = app.AccountKeeper.ValidatePermissions(otherAcc) + require.Error(t, err) +} diff --git a/x/auth/module.go b/x/auth/module.go index 8ebc12a76623..3c3a9acf0cbc 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -77,15 +77,13 @@ type AppModule struct { AppModuleBasic accountKeeper AccountKeeper - bankKeeper types.BankKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(accountKeeper AccountKeeper, bankKeeper types.BankKeeper) AppModule { +func NewAppModule(accountKeeper AccountKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, accountKeeper: accountKeeper, - bankKeeper: bankKeeper, } } @@ -118,7 +116,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.accountKeeper, am.bankKeeper, genesisState) + InitGenesis(ctx, am.accountKeeper, genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/auth/module_test.go b/x/auth/module_test.go index e1028347bac2..f0789b2cdcac 100644 --- a/x/auth/module_test.go +++ b/x/auth/module_test.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank" ) func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { @@ -22,6 +21,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { }, ) - acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(auth.FeeCollectorName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(auth.FeeCollectorName)) require.NotNil(t, acc) } diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 8be072d1d169..35202f30a65b 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -4,6 +4,8 @@ import ( "bytes" "encoding/json" "errors" + "fmt" + "strings" "github.com/tendermint/tendermint/crypto" yaml "gopkg.in/yaml.v2" @@ -12,8 +14,12 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -var _ exported.Account = (*BaseAccount)(nil) -var _ exported.GenesisAccount = (*BaseAccount)(nil) +var ( + _ exported.Account = (*BaseAccount)(nil) + _ exported.GenesisAccount = (*BaseAccount)(nil) + _ exported.GenesisAccount = (*ModuleAccount)(nil) + _ exported.ModuleAccountI = (*ModuleAccount)(nil) +) // NewBaseAccount creates a new BaseAccount object func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, sequence uint64) *BaseAccount { @@ -188,3 +194,137 @@ func (acc *BaseAccount) UnmarshalJSON(bz []byte) error { return nil } + +// NewModuleAddress creates an AccAddress from the hash of the module's name +func NewModuleAddress(name string) sdk.AccAddress { + return sdk.AccAddress(crypto.AddressHash([]byte(name))) +} + +// NewEmptyModuleAccount creates a empty ModuleAccount from a string +func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { + moduleAddress := NewModuleAddress(name) + baseAcc := NewBaseAccountWithAddress(moduleAddress) + + if err := validatePermissions(permissions...); err != nil { + panic(err) + } + + return &ModuleAccount{ + BaseAccount: baseAcc, + Name: name, + Permissions: permissions, + } +} + +// NewModuleAccount creates a new ModuleAccount instance +func NewModuleAccount(ba *BaseAccount, name string, permissions ...string) *ModuleAccount { + if err := validatePermissions(permissions...); err != nil { + panic(err) + } + + return &ModuleAccount{ + BaseAccount: ba, + Name: name, + Permissions: permissions, + } +} + +// HasPermission returns whether or not the module account has permission. +func (ma ModuleAccount) HasPermission(permission string) bool { + for _, perm := range ma.Permissions { + if perm == permission { + return true + } + } + return false +} + +// GetName returns the the name of the holder's module +func (ma ModuleAccount) GetName() string { + return ma.Name +} + +// GetPermissions returns permissions granted to the module account +func (ma ModuleAccount) GetPermissions() []string { + return ma.Permissions +} + +// SetPubKey - Implements Account +func (ma ModuleAccount) SetPubKey(pubKey crypto.PubKey) error { + return fmt.Errorf("not supported for module accounts") +} + +// SetSequence - Implements Account +func (ma ModuleAccount) SetSequence(seq uint64) error { + return fmt.Errorf("not supported for module accounts") +} + +// Validate checks for errors on the account fields +func (ma ModuleAccount) Validate() error { + if strings.TrimSpace(ma.Name) == "" { + return errors.New("module account name cannot be blank") + } + if !ma.Address.Equals(sdk.AccAddress(crypto.AddressHash([]byte(ma.Name)))) { + return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) + } + + return ma.BaseAccount.Validate() +} + +type moduleAccountPretty struct { + Address sdk.AccAddress `json:"address" yaml:"address"` + PubKey string `json:"public_key" yaml:"public_key"` + AccountNumber uint64 `json:"account_number" yaml:"account_number"` + Sequence uint64 `json:"sequence" yaml:"sequence"` + Name string `json:"name" yaml:"name"` + Permissions []string `json:"permissions" yaml:"permissions"` +} + +func (ma ModuleAccount) String() string { + out, _ := ma.MarshalYAML() + return out.(string) +} + +// MarshalYAML returns the YAML representation of a ModuleAccount. +func (ma ModuleAccount) MarshalYAML() (interface{}, error) { + bs, err := yaml.Marshal(moduleAccountPretty{ + Address: ma.Address, + PubKey: "", + AccountNumber: ma.AccountNumber, + Sequence: ma.Sequence, + Name: ma.Name, + Permissions: ma.Permissions, + }) + + if err != nil { + return nil, err + } + + return string(bs), nil +} + +// MarshalJSON returns the JSON representation of a ModuleAccount. +func (ma ModuleAccount) MarshalJSON() ([]byte, error) { + return json.Marshal(moduleAccountPretty{ + Address: ma.Address, + PubKey: "", + AccountNumber: ma.AccountNumber, + Sequence: ma.Sequence, + Name: ma.Name, + Permissions: ma.Permissions, + }) +} + +// UnmarshalJSON unmarshals raw JSON bytes into a ModuleAccount. +func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error { + var alias moduleAccountPretty + if err := json.Unmarshal(bz, &alias); err != nil { + return err + } + + ma.BaseAccount = NewBaseAccount(alias.Address, nil, alias.AccountNumber, alias.Sequence) + ma.Name = alias.Name + ma.Permissions = alias.Permissions + + return nil +} diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index ca612f1fe188..9e156c49da8d 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -1,10 +1,14 @@ package types_test import ( + "encoding/json" + "errors" + "fmt" "testing" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/secp256k1" + yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" @@ -107,3 +111,87 @@ func TestGenesisAccountValidate(t *testing.T) { }) } } + +func TestModuleAccountMarshalYAML(t *testing.T) { + name := "test" + moduleAcc := types.NewEmptyModuleAccount(name, types.Minter, types.Burner, types.Staking) + bs, err := yaml.Marshal(moduleAcc) + require.NoError(t, err) + + want := "|\n address: cosmos1n7rdpqvgf37ktx30a2sv2kkszk3m7ncmg5drhe\n public_key: \"\"\n account_number: 0\n sequence: 0\n name: test\n permissions:\n - minter\n - burner\n - staking\n" + require.Equal(t, want, string(bs)) +} + +func TestHasPermissions(t *testing.T) { + name := "test" + macc := types.NewEmptyModuleAccount(name, types.Staking, types.Minter, types.Burner) + cases := []struct { + permission string + expectHas bool + }{ + {types.Staking, true}, + {types.Minter, true}, + {types.Burner, true}, + {"other", false}, + } + + for i, tc := range cases { + hasPerm := macc.HasPermission(tc.permission) + if tc.expectHas { + require.True(t, hasPerm, "test case #%d", i) + } else { + require.False(t, hasPerm, "test case #%d", i) + } + } +} + +func TestValidate(t *testing.T) { + addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + baseAcc := types.NewBaseAccount(addr, nil, 0, 0) + tests := []struct { + name string + acc exported.GenesisAccount + expErr error + }{ + { + "valid module account", + types.NewEmptyModuleAccount("test"), + nil, + }, + { + "invalid name and address pair", + types.NewModuleAccount(baseAcc, "test"), + fmt.Errorf("address %s cannot be derived from the module name 'test'", addr), + }, + { + "empty module account name", + types.NewModuleAccount(baseAcc, " "), + errors.New("module account name cannot be blank"), + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + err := tt.acc.Validate() + require.Equal(t, tt.expErr, err) + }) + } +} + +func TestModuleAccountJSON(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + baseAcc := types.NewBaseAccount(addr, nil, 10, 50) + acc := types.NewModuleAccount(baseAcc, "test", "burner") + + bz, err := json.Marshal(acc) + require.NoError(t, err) + + bz1, err := acc.MarshalJSON() + require.NoError(t, err) + require.Equal(t, string(bz1), string(bz)) + + var a types.ModuleAccount + require.NoError(t, json.Unmarshal(bz, &a)) + require.Equal(t, acc.String(), a.String()) +} diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 53de61568a1a..b4be63155daa 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -20,9 +20,11 @@ type Codec interface { // RegisterCodec registers the account interfaces and concrete types on the // provided Amino codec. func RegisterCodec(cdc *codec.Codec) { + cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) cdc.RegisterInterface((*exported.GenesisAccount)(nil), nil) cdc.RegisterInterface((*exported.Account)(nil), nil) cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil) + cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index 9bcc6714aa4d..0ab3f9c4308e 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -2,12 +2,9 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" ) // BankKeeper defines the contract needed for supply related APIs (noalias) type BankKeeper interface { SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI - GetModuleAddress(moduleName string) sdk.AccAddress } diff --git a/x/bank/types/permissions.go b/x/auth/types/permissions.go similarity index 100% rename from x/bank/types/permissions.go rename to x/auth/types/permissions.go diff --git a/x/bank/types/permissions_test.go b/x/auth/types/permissions_test.go similarity index 100% rename from x/bank/types/permissions_test.go rename to x/auth/types/permissions_test.go diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go index ea6e34debdd0..ad102a4ce8e7 100644 --- a/x/auth/types/types.pb.go +++ b/x/auth/types/types.pb.go @@ -66,6 +66,45 @@ func (m *BaseAccount) XXX_DiscardUnknown() { var xxx_messageInfo_BaseAccount proto.InternalMessageInfo +// ModuleAccount defines an account for modules that holds coins on a pool +type ModuleAccount struct { + *BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty" yaml:"base_account"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty"` +} + +func (m *ModuleAccount) Reset() { *m = ModuleAccount{} } +func (*ModuleAccount) ProtoMessage() {} +func (*ModuleAccount) Descriptor() ([]byte, []int) { + return fileDescriptor_2d526fa662daab74, []int{1} +} +func (m *ModuleAccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ModuleAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ModuleAccount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ModuleAccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModuleAccount.Merge(m, src) +} +func (m *ModuleAccount) XXX_Size() int { + return m.Size() +} +func (m *ModuleAccount) XXX_DiscardUnknown() { + xxx_messageInfo_ModuleAccount.DiscardUnknown(m) +} + +var xxx_messageInfo_ModuleAccount proto.InternalMessageInfo + // Params defines the parameters for the auth module. type Params struct { MaxMemoCharacters uint64 `protobuf:"varint,1,opt,name=max_memo_characters,json=maxMemoCharacters,proto3" json:"max_memo_characters,omitempty" yaml:"max_memo_characters"` @@ -78,7 +117,7 @@ type Params struct { func (m *Params) Reset() { *m = Params{} } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_2d526fa662daab74, []int{1} + return fileDescriptor_2d526fa662daab74, []int{2} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -144,48 +183,54 @@ func (m *Params) GetSigVerifyCostSecp256k1() uint64 { func init() { proto.RegisterType((*BaseAccount)(nil), "cosmos_sdk.x.auth.v1.BaseAccount") + proto.RegisterType((*ModuleAccount)(nil), "cosmos_sdk.x.auth.v1.ModuleAccount") proto.RegisterType((*Params)(nil), "cosmos_sdk.x.auth.v1.Params") } func init() { proto.RegisterFile("x/auth/types/types.proto", fileDescriptor_2d526fa662daab74) } var fileDescriptor_2d526fa662daab74 = []byte{ - // 558 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0x3f, 0x6f, 0xd3, 0x40, - 0x14, 0x8f, 0xdb, 0xd0, 0x56, 0x47, 0x41, 0xaa, 0x9b, 0xb6, 0x6e, 0x85, 0x7c, 0x91, 0x07, 0x54, - 0x24, 0x9a, 0x28, 0x45, 0x41, 0x6a, 0x06, 0x44, 0x1c, 0x60, 0x29, 0x54, 0x95, 0x23, 0x31, 0xb0, - 0x58, 0xe7, 0xf3, 0xe1, 0x58, 0xc9, 0xe5, 0x5c, 0xdf, 0xb9, 0xb2, 0xfb, 0x09, 0x10, 0x13, 0x23, - 0x63, 0x3e, 0x0e, 0x63, 0x47, 0x26, 0x83, 0x92, 0x05, 0x31, 0x7a, 0x64, 0x42, 0xf6, 0xa5, 0x69, - 0x52, 0x05, 0x16, 0xdb, 0xef, 0xfd, 0xfe, 0x9d, 0x9e, 0xef, 0x01, 0x2d, 0xae, 0xa3, 0x48, 0xf4, - 0xea, 0x22, 0x09, 0x08, 0x97, 0xcf, 0x5a, 0x10, 0x32, 0xc1, 0xd4, 0x0a, 0x66, 0x9c, 0x32, 0x6e, - 0x73, 0xb7, 0x5f, 0x8b, 0x6b, 0x39, 0xa9, 0x76, 0xd9, 0x38, 0x78, 0x2c, 0x7a, 0x7e, 0xe8, 0xda, - 0x01, 0x0a, 0x45, 0x52, 0x2f, 0x88, 0x75, 0x8f, 0x79, 0xec, 0xf6, 0x4b, 0xaa, 0x8d, 0xcf, 0x2b, - 0xe0, 0xbe, 0x89, 0x38, 0x69, 0x63, 0xcc, 0xa2, 0xa1, 0x50, 0x4f, 0xc1, 0x3a, 0x72, 0xdd, 0x90, - 0x70, 0xae, 0x29, 0x55, 0xe5, 0x70, 0xd3, 0x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x87, 0x27, 0xff, 0xbd, 0xe3, 0xf3, 0xdb, 0xe7, 0xac, 0x15, 0xab, 0xf3, 0xec, - 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc4, 0x8c, 0x0a, 0xa8, 0x94, 0x03, 0x00, 0x00, + // 640 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xbf, 0x6f, 0xd3, 0x40, + 0x14, 0x8e, 0x9b, 0xd0, 0x1f, 0x97, 0x16, 0xa9, 0x6e, 0xda, 0xba, 0x05, 0xf9, 0x82, 0x07, 0x54, + 0x24, 0xea, 0x28, 0x45, 0x45, 0x6a, 0x06, 0x44, 0x5d, 0x60, 0x29, 0xad, 0xaa, 0xab, 0xc4, 0xc0, + 0x62, 0x9d, 0xed, 0x23, 0xb1, 0x92, 0xcb, 0xb9, 0xbe, 0x73, 0x15, 0xf7, 0x2f, 0x40, 0x4c, 0x8c, + 0x8c, 0xfd, 0x1b, 0xf8, 0x2b, 0x18, 0x3b, 0x32, 0x19, 0x94, 0x2e, 0x88, 0xd1, 0x23, 0x13, 0xb2, + 0x2f, 0x4d, 0x9d, 0x2a, 0xb0, 0xd8, 0xf7, 0xde, 0xfb, 0xbe, 0xef, 0x3d, 0x7f, 0x4f, 0x67, 0xa0, + 0x0d, 0x1a, 0x38, 0x12, 0x9d, 0x86, 0x88, 0x03, 0xc2, 0xe5, 0xd3, 0x0c, 0x42, 0x26, 0x98, 0x5a, + 0x73, 0x19, 0xa7, 0x8c, 0xdb, 0xdc, 0xeb, 0x9a, 0x03, 0x33, 0x03, 0x99, 0xe7, 0xcd, 0xcd, 0xc7, + 0xa2, 0xe3, 0x87, 0x9e, 0x1d, 0xe0, 0x50, 0xc4, 0x8d, 0x1c, 0xd8, 0x68, 0xb3, 0x36, 0xbb, 0x3d, + 0x49, 0xb6, 0xf1, 0x69, 0x06, 0x54, 0x2d, 0xcc, 0x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0xb0, 0x76, 0xea, 0xb7, 0xdf, 0xe5, 0x88, 0x8c, 0xfa, 0xfa, + 0x55, 0x5e, 0x4f, 0x13, 0xa8, 0xcb, 0x6e, 0xff, 0x10, 0x30, 0x50, 0x8d, 0x4f, 0xf0, 0x64, 0x5a, + 0x8d, 0xc1, 0xc6, 0x5d, 0x06, 0x27, 0x6e, 0xb0, 0xb3, 0xfb, 0xbc, 0xdb, 0xd4, 0xee, 0xe5, 0x4d, + 0x5f, 0x0c, 0x13, 0xb8, 0x36, 0xd1, 0xf4, 0xf4, 0x06, 0x91, 0x26, 0xb0, 0x3e, 0xbd, 0xed, 0x58, + 0xc4, 0x40, 0x6b, 0x7c, 0x2a, 0xb7, 0x35, 0x9f, 0x6d, 0xf7, 0xd7, 0x25, 0x54, 0xac, 0x83, 0x6f, + 0x43, 0x5d, 0xb9, 0x1a, 0xea, 0xca, 0xcf, 0xa1, 0xae, 0x7c, 0xbe, 0xd6, 0x4b, 0x57, 0xd7, 0x7a, + 0xe9, 0xfb, 0xb5, 0x5e, 0x7a, 0xff, 0xe4, 0xbf, 0x17, 0xb3, 0xf8, 0xcb, 0x70, 0x66, 0xf3, 0xfb, + 0xfe, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x00, 0xf0, 0x01, 0x49, 0x04, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -271,6 +316,57 @@ func (m *BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ModuleAccount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -353,6 +449,29 @@ func (m *BaseAccount) Size() (n int) { return n } +func (m *ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + func (m *Params) Size() (n int) { if m == nil { return 0 @@ -542,6 +661,159 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error { } return nil } +func (m *ModuleAccount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ModuleAccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ModuleAccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BaseAccount == nil { + m.BaseAccount = &BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/auth/types/types.proto b/x/auth/types/types.proto index f18fce96b3fc..49185dbb16d4 100644 --- a/x/auth/types/types.proto +++ b/x/auth/types/types.proto @@ -18,6 +18,16 @@ message BaseAccount { uint64 sequence = 4; } +// ModuleAccount defines an account for modules that holds coins on a pool +message ModuleAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; + string name = 2; + repeated string permissions = 3; +} + // Params defines the parameters for the auth module. message Params { option (gogoproto.equal) = true; @@ -27,8 +37,7 @@ message Params { uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; uint64 sig_verify_cost_ed25519 = 4 - [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; + [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; uint64 sig_verify_cost_secp256k1 = 5 - [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; + [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; } - diff --git a/x/bank/alias.go b/x/bank/alias.go index 7c5ba8a17bcf..aba6838199c8 100644 --- a/x/bank/alias.go +++ b/x/bank/alias.go @@ -22,9 +22,6 @@ const ( StoreKey = types.StoreKey RouterKey = types.RouterKey QuerierRoute = types.QuerierRoute - Minter = types.Minter - Burner = types.Burner - Staking = types.Staking ) var ( @@ -57,9 +54,6 @@ var ( AddressFromBalancesStore = types.AddressFromBalancesStore AllInvariants = keeper.AllInvariants TotalSupply = keeper.TotalSupply - NewModuleAddress = types.NewModuleAddress - NewEmptyModuleAccount = types.NewEmptyModuleAccount - NewModuleAccount = types.NewModuleAccount NewSupply = types.NewSupply DefaultSupply = types.DefaultSupply ) @@ -79,7 +73,6 @@ type ( QueryAllBalancesParams = types.QueryAllBalancesParams GenesisBalancesIterator = types.GenesisBalancesIterator Keeper = keeper.Keeper - ModuleAccount = types.ModuleAccount GenesisState = types.GenesisState Supply = types.Supply Codec = types.Codec diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 8fae240d9886..47bbee7c7221 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/distribution" abci "github.com/tendermint/tendermint/abci/types" @@ -147,7 +146,7 @@ func TestSendToModuleAcc(t *testing.T) { { name: "Allowed module account can be the recipient of bank sends", fromBalance: coins, - msg: types.NewMsgSend(addr1, bank.NewModuleAddress(distribution.ModuleName), coins), + msg: types.NewMsgSend(addr1, auth.NewModuleAddress(distribution.ModuleName), coins), expPass: true, expSimPass: true, expFromBalance: sdk.NewCoins(), diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index c52439698517..4bc978c3fcdf 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -10,11 +10,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/staking" ) -var moduleAccAddr = bank.NewModuleAddress(staking.BondedPoolName) +var moduleAccAddr = auth.NewModuleAddress(staking.BondedPoolName) func BenchmarkOneBankSendTxPerBlock(b *testing.B) { // Add an account at genesis diff --git a/x/bank/exported/exported.go b/x/bank/exported/exported.go index 27806aa14f67..cee67909f536 100644 --- a/x/bank/exported/exported.go +++ b/x/bank/exported/exported.go @@ -2,7 +2,6 @@ package exported import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // GenesisBalance defines a genesis balance interface that allows for account @@ -12,16 +11,6 @@ type GenesisBalance interface { GetCoins() sdk.Coins } -// ModuleAccountI defines an account interface for modules that hold tokens in -// an escrow. -type ModuleAccountI interface { - authexported.Account - - GetName() string - GetPermissions() []string - HasPermission(string) bool -} - // SupplyI defines an inflationary supply interface for modules that handle // token supply. type SupplyI interface { diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 194346e504a9..4de3b0a41f5c 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -6,6 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -22,14 +23,6 @@ type Keeper interface { GetSupply(ctx sdk.Context) exported.SupplyI SetSupply(ctx sdk.Context, supply exported.SupplyI) - ValidatePermissions(macc exported.ModuleAccountI) error - - GetModuleAddress(moduleName string) sdk.AccAddress - GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) - GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) - GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI - SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error @@ -50,12 +43,11 @@ type BaseKeeper struct { cdc types.Codec storeKey sdk.StoreKey paramSpace paramtypes.Subspace - permAddrs map[string]types.PermissionsForAddress } func NewBaseKeeper( cdc types.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, paramSpace paramtypes.Subspace, - blacklistedAddrs map[string]bool, maccPerms map[string][]string, + blacklistedAddrs map[string]bool, ) BaseKeeper { // set KeyTable if it has not already been set @@ -63,18 +55,12 @@ func NewBaseKeeper( paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) } - permAddrs := make(map[string]types.PermissionsForAddress) - for name, perms := range maccPerms { - permAddrs[name] = types.NewPermissionsForAddress(name, perms) - } - return BaseKeeper{ BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, paramSpace, blacklistedAddrs), ak: ak, cdc: cdc, storeKey: storeKey, paramSpace: paramSpace, - permAddrs: permAddrs, } } @@ -181,83 +167,13 @@ func (k BaseKeeper) SetSupply(ctx sdk.Context, supply exported.SupplyI) { store.Set(types.SupplyKey, bz) } -// ValidatePermissions validates that the module account has been granted -// permissions within its set of allowed permissions. -func (k BaseKeeper) ValidatePermissions(macc exported.ModuleAccountI) error { - permAddr := k.permAddrs[macc.GetName()] - for _, perm := range macc.GetPermissions() { - if !permAddr.HasPermission(perm) { - return fmt.Errorf("invalid module permission %s", perm) - } - } - - return nil -} - -// GetModuleAddress returns an address based on the module name -func (k BaseKeeper) GetModuleAddress(moduleName string) sdk.AccAddress { - permAddr, ok := k.permAddrs[moduleName] - if !ok { - return nil - } - - return permAddr.GetAddress() -} - -// GetModuleAddressAndPermissions returns an address and permissions based on the module name -func (k BaseKeeper) GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) { - permAddr, ok := k.permAddrs[moduleName] - if !ok { - return addr, permissions - } - - return permAddr.GetAddress(), permAddr.GetPermissions() -} - -// GetModuleAccountAndPermissions gets the module account from the auth account store and its -// registered permissions -func (k BaseKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) { - addr, perms := k.GetModuleAddressAndPermissions(moduleName) - if addr == nil { - return nil, []string{} - } - - acc := k.ak.GetAccount(ctx, addr) - if acc != nil { - macc, ok := acc.(exported.ModuleAccountI) - if !ok { - panic("account is not a module account") - } - return macc, perms - } - - // create a new module account - macc := types.NewEmptyModuleAccount(moduleName, perms...) - maccI := (k.ak.NewAccount(ctx, macc)).(exported.ModuleAccountI) // set the account number - k.SetModuleAccount(ctx, maccI) - - return maccI, perms -} - -// GetModuleAccount gets the module account from the auth account store, if the account does not -// exist in the AccountKeeper, then it is created. -func (k BaseKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI { - acc, _ := k.GetModuleAccountAndPermissions(ctx, moduleName) - return acc -} - -// SetModuleAccount sets the module account to the auth account store -func (k BaseKeeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) { //nolint:interfacer - k.ak.SetAccount(ctx, macc) -} - // SendCoinsFromModuleToAccount transfers coins from a ModuleAccount to an AccAddress. // It will panic if the module account does not exist. func (k BaseKeeper) SendCoinsFromModuleToAccount( ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins, ) error { - senderAddr := k.GetModuleAddress(senderModule) + senderAddr := k.ak.GetModuleAddress(senderModule) if senderAddr == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)) } @@ -271,12 +187,12 @@ func (k BaseKeeper) SendCoinsFromModuleToModule( ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins, ) error { - senderAddr := k.GetModuleAddress(senderModule) + senderAddr := k.ak.GetModuleAddress(senderModule) if senderAddr == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)) } - recipientAcc := k.GetModuleAccount(ctx, recipientModule) + recipientAcc := k.ak.GetModuleAccount(ctx, recipientModule) if recipientAcc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule)) } @@ -290,7 +206,7 @@ func (k BaseKeeper) SendCoinsFromAccountToModule( ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins, ) error { - recipientAcc := k.GetModuleAccount(ctx, recipientModule) + recipientAcc := k.ak.GetModuleAccount(ctx, recipientModule) if recipientAcc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule)) } @@ -305,12 +221,12 @@ func (k BaseKeeper) DelegateCoinsFromAccountToModule( ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins, ) error { - recipientAcc := k.GetModuleAccount(ctx, recipientModule) + recipientAcc := k.ak.GetModuleAccount(ctx, recipientModule) if recipientAcc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", recipientModule)) } - if !recipientAcc.HasPermission(types.Staking) { + if !recipientAcc.HasPermission(auth.Staking) { panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to receive delegated coins", recipientModule)) } @@ -324,12 +240,12 @@ func (k BaseKeeper) UndelegateCoinsFromModuleToAccount( ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins, ) error { - acc := k.GetModuleAccount(ctx, senderModule) + acc := k.ak.GetModuleAccount(ctx, senderModule) if acc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", senderModule)) } - if !acc.HasPermission(types.Staking) { + if !acc.HasPermission(auth.Staking) { panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to undelegate coins", senderModule)) } @@ -339,12 +255,12 @@ func (k BaseKeeper) UndelegateCoinsFromModuleToAccount( // MintCoins creates new coins from thin air and adds it to the module account. // It will panic if the module account does not exist or is unauthorized. func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { - acc := k.GetModuleAccount(ctx, moduleName) + acc := k.ak.GetModuleAccount(ctx, moduleName) if acc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleName)) } - if !acc.HasPermission(types.Minter) { + if !acc.HasPermission(auth.Minter) { panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to mint tokens", moduleName)) } @@ -368,12 +284,12 @@ func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) // BurnCoins burns coins deletes coins from the balance of the module account. // It will panic if the module account does not exist or is unauthorized. func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { - acc := k.GetModuleAccount(ctx, moduleName) + acc := k.ak.GetModuleAccount(ctx, moduleName) if acc == nil { panic(sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleName)) } - if !acc.HasPermission(types.Burner) { + if !acc.HasPermission(auth.Burner) { panic(sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "module account %s does not have permissions to burn tokens", moduleName)) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index fe6f664d682f..ee3de2b6b0e4 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -28,11 +28,11 @@ const ( ) var ( - holderAcc = types.NewEmptyModuleAccount(holder) - burnerAcc = types.NewEmptyModuleAccount(types.Burner, types.Burner) - minterAcc = types.NewEmptyModuleAccount(types.Minter, types.Minter) - multiPermAcc = types.NewEmptyModuleAccount(multiPerm, types.Burner, types.Minter, types.Staking) - randomPermAcc = types.NewEmptyModuleAccount(randomPerm, "random") + holderAcc = auth.NewEmptyModuleAccount(holder) + burnerAcc = auth.NewEmptyModuleAccount(auth.Burner, auth.Burner) + minterAcc = auth.NewEmptyModuleAccount(auth.Minter, auth.Minter) + multiPermAcc = auth.NewEmptyModuleAccount(multiPerm, auth.Burner, auth.Minter, auth.Staking) + randomPermAcc = auth.NewEmptyModuleAccount(randomPerm, "random") initTokens = sdk.TokensFromConsensusPower(initialPower) initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)) @@ -48,7 +48,7 @@ func newBarCoin(amt int64) sdk.Coin { // nolint: interfacer func getCoinsByName(ctx sdk.Context, bk bank.Keeper, ak types.AccountKeeper, moduleName string) sdk.Coins { - moduleAddress := bk.GetModuleAddress(moduleName) + moduleAddress := ak.GetModuleAddress(moduleName) macc := ak.GetAccount(ctx, moduleAddress) if macc == nil { return sdk.Coins(nil) @@ -75,35 +75,6 @@ func (suite *IntegrationTestSuite) SetupTest() { suite.ctx = ctx } -func (suite *IntegrationTestSuite) TestSupply_ValidatePermissions() { - app := suite.app - - // add module accounts to supply keeper - maccPerms := simapp.GetMaccPerms() - maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} - maccPerms[randomPerm] = []string{"random"} - - appCodec := codecstd.NewAppCodec(app.Codec()) - keeper := bank.NewBaseKeeper( - appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, - app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms, - ) - - err := keeper.ValidatePermissions(multiPermAcc) - suite.Require().NoError(err) - - err = keeper.ValidatePermissions(randomPermAcc) - suite.Require().NoError(err) - - // unregistered permissions - otherAcc := types.NewEmptyModuleAccount("other", "other") - err = app.BankKeeper.ValidatePermissions(otherAcc) - suite.Require().Error(err) -} - func (suite *IntegrationTestSuite) TestSupply() { app, ctx := suite.app, suite.ctx @@ -125,30 +96,34 @@ func (suite *IntegrationTestSuite) TestSupply_SendCoins() { // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[auth.Burner] = []string{auth.Burner} + maccPerms[auth.Minter] = []string{auth.Minter} + maccPerms[multiPerm] = []string{auth.Burner, auth.Minter, auth.Staking} maccPerms[randomPerm] = []string{"random"} + authKeeper := auth.NewAccountKeeper( + appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), + auth.ProtoBaseAccount, maccPerms, + ) keeper := bank.NewBaseKeeper( - appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, - app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms, + appCodec, app.GetKey(types.StoreKey), authKeeper, + app.GetSubspace(bank.ModuleName), make(map[string]bool), ) - baseAcc := app.AccountKeeper.NewAccountWithAddress(ctx, types.NewModuleAddress("baseAcc")) + baseAcc := authKeeper.NewAccountWithAddress(ctx, auth.NewModuleAddress("baseAcc")) suite.Require().NoError(keeper.SetBalances(ctx, holderAcc.GetAddress(), initCoins)) - keeper.SetSupply(ctx, types.NewSupply(initCoins)) - keeper.SetModuleAccount(ctx, holderAcc) - keeper.SetModuleAccount(ctx, burnerAcc) - app.AccountKeeper.SetAccount(ctx, baseAcc) + keeper.SetSupply(ctx, types.NewSupply(initCoins)) + authKeeper.SetModuleAccount(ctx, holderAcc) + authKeeper.SetModuleAccount(ctx, burnerAcc) + authKeeper.SetAccount(ctx, baseAcc) suite.Require().Panics(func() { keeper.SendCoinsFromModuleToModule(ctx, "", holderAcc.GetName(), initCoins) // nolint:errcheck }) suite.Require().Panics(func() { - keeper.SendCoinsFromModuleToModule(ctx, types.Burner, "", initCoins) // nolint:errcheck + keeper.SendCoinsFromModuleToModule(ctx, auth.Burner, "", initCoins) // nolint:errcheck }) suite.Require().Panics(func() { @@ -160,20 +135,20 @@ func (suite *IntegrationTestSuite) TestSupply_SendCoins() { ) suite.Require().NoError( - keeper.SendCoinsFromModuleToModule(ctx, holderAcc.GetName(), types.Burner, initCoins), + keeper.SendCoinsFromModuleToModule(ctx, holderAcc.GetName(), auth.Burner, initCoins), ) - suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, holderAcc.GetName())) - suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner)) + suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, authKeeper, holderAcc.GetName())) + suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, authKeeper, auth.Burner)) suite.Require().NoError( - keeper.SendCoinsFromModuleToAccount(ctx, types.Burner, baseAcc.GetAddress(), initCoins), + keeper.SendCoinsFromModuleToAccount(ctx, auth.Burner, baseAcc.GetAddress(), initCoins), ) - suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner)) + suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, authKeeper, auth.Burner)) suite.Require().Equal(initCoins, keeper.GetAllBalances(ctx, baseAcc.GetAddress())) - suite.Require().NoError(keeper.SendCoinsFromAccountToModule(ctx, baseAcc.GetAddress(), types.Burner, initCoins)) + suite.Require().NoError(keeper.SendCoinsFromAccountToModule(ctx, baseAcc.GetAddress(), auth.Burner, initCoins)) suite.Require().Equal(sdk.Coins(nil), keeper.GetAllBalances(ctx, baseAcc.GetAddress())) - suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner)) + suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, authKeeper, auth.Burner)) } func (suite *IntegrationTestSuite) TestSupply_MintCoins() { @@ -184,35 +159,39 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() { // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[auth.Burner] = []string{auth.Burner} + maccPerms[auth.Minter] = []string{auth.Minter} + maccPerms[multiPerm] = []string{auth.Burner, auth.Minter, auth.Staking} maccPerms[randomPerm] = []string{"random"} + authKeeper := auth.NewAccountKeeper( + appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), + auth.ProtoBaseAccount, maccPerms, + ) keeper := bank.NewBaseKeeper( - appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, - app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms, + appCodec, app.GetKey(types.StoreKey), authKeeper, + app.GetSubspace(bank.ModuleName), make(map[string]bool), ) - keeper.SetModuleAccount(ctx, burnerAcc) - keeper.SetModuleAccount(ctx, minterAcc) - keeper.SetModuleAccount(ctx, multiPermAcc) - keeper.SetModuleAccount(ctx, randomPermAcc) + authKeeper.SetModuleAccount(ctx, burnerAcc) + authKeeper.SetModuleAccount(ctx, minterAcc) + authKeeper.SetModuleAccount(ctx, multiPermAcc) + authKeeper.SetModuleAccount(ctx, randomPermAcc) initialSupply := keeper.GetSupply(ctx) - suite.Require().Panics(func() { keeper.MintCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck - suite.Require().Panics(func() { keeper.MintCoins(ctx, types.Burner, initCoins) }, "invalid permission") // nolint:errcheck + suite.Require().Panics(func() { keeper.MintCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck + suite.Require().Panics(func() { keeper.MintCoins(ctx, auth.Burner, initCoins) }, "invalid permission") // nolint:errcheck - err := keeper.MintCoins(ctx, types.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}}) + err := keeper.MintCoins(ctx, auth.Minter, sdk.Coins{sdk.Coin{Denom: "denom", Amount: sdk.NewInt(-10)}}) suite.Require().Error(err, "insufficient coins") suite.Require().Panics(func() { keeper.MintCoins(ctx, randomPerm, initCoins) }) // nolint:errcheck - err = keeper.MintCoins(ctx, types.Minter, initCoins) + err = keeper.MintCoins(ctx, auth.Minter, initCoins) suite.Require().NoError(err) - suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, types.Minter)) + suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, authKeeper, auth.Minter)) suite.Require().Equal(initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal()) // test same functionality on module account with multiple permissions @@ -221,9 +200,9 @@ func (suite *IntegrationTestSuite) TestSupply_MintCoins() { err = keeper.MintCoins(ctx, multiPermAcc.GetName(), initCoins) suite.Require().NoError(err) - suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, app.AccountKeeper, multiPermAcc.GetName())) + suite.Require().Equal(initCoins, getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName())) suite.Require().Equal(initialSupply.GetTotal().Add(initCoins...), keeper.GetSupply(ctx).GetTotal()) - suite.Require().Panics(func() { keeper.MintCoins(ctx, types.Burner, initCoins) }) // nolint:errcheck + suite.Require().Panics(func() { keeper.MintCoins(ctx, auth.Burner, initCoins) }) // nolint:errcheck } func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { @@ -234,33 +213,37 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { // add module accounts to supply keeper maccPerms := simapp.GetMaccPerms() maccPerms[holder] = nil - maccPerms[types.Burner] = []string{types.Burner} - maccPerms[types.Minter] = []string{types.Minter} - maccPerms[multiPerm] = []string{types.Burner, types.Minter, types.Staking} + maccPerms[auth.Burner] = []string{auth.Burner} + maccPerms[auth.Minter] = []string{auth.Minter} + maccPerms[multiPerm] = []string{auth.Burner, auth.Minter, auth.Staking} maccPerms[randomPerm] = []string{"random"} + authKeeper := auth.NewAccountKeeper( + appCodec, app.GetKey(types.StoreKey), app.GetSubspace(types.ModuleName), + auth.ProtoBaseAccount, maccPerms, + ) keeper := bank.NewBaseKeeper( - appCodec, app.GetKey(types.StoreKey), app.AccountKeeper, - app.GetSubspace(bank.ModuleName), make(map[string]bool), maccPerms, + appCodec, app.GetKey(types.StoreKey), authKeeper, + app.GetSubspace(bank.ModuleName), make(map[string]bool), ) suite.Require().NoError(keeper.SetBalances(ctx, burnerAcc.GetAddress(), initCoins)) keeper.SetSupply(ctx, types.NewSupply(initCoins)) - keeper.SetModuleAccount(ctx, burnerAcc) + authKeeper.SetModuleAccount(ctx, burnerAcc) initialSupply := keeper.GetSupply(ctx) initialSupply.Inflate(initCoins) keeper.SetSupply(ctx, initialSupply) suite.Require().Panics(func() { keeper.BurnCoins(ctx, "", initCoins) }, "no module account") // nolint:errcheck - suite.Require().Panics(func() { keeper.BurnCoins(ctx, types.Minter, initCoins) }, "invalid permission") // nolint:errcheck + suite.Require().Panics(func() { keeper.BurnCoins(ctx, auth.Minter, initCoins) }, "invalid permission") // nolint:errcheck suite.Require().Panics(func() { keeper.BurnCoins(ctx, randomPerm, initialSupply.GetTotal()) }, "random permission") // nolint:errcheck - err := keeper.BurnCoins(ctx, types.Burner, initialSupply.GetTotal()) + err := keeper.BurnCoins(ctx, auth.Burner, initialSupply.GetTotal()) suite.Require().Error(err, "insufficient coins") - err = keeper.BurnCoins(ctx, types.Burner, initCoins) + err = keeper.BurnCoins(ctx, auth.Burner, initCoins) suite.Require().NoError(err) - suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, types.Burner)) + suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, authKeeper, auth.Burner)) suite.Require().Equal(initialSupply.GetTotal().Sub(initCoins), keeper.GetSupply(ctx).GetTotal()) // test same functionality on module account with multiple permissions @@ -269,11 +252,11 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() { keeper.SetSupply(ctx, initialSupply) suite.Require().NoError(keeper.SetBalances(ctx, multiPermAcc.GetAddress(), initCoins)) - keeper.SetModuleAccount(ctx, multiPermAcc) + authKeeper.SetModuleAccount(ctx, multiPermAcc) err = keeper.BurnCoins(ctx, multiPermAcc.GetName(), initCoins) suite.Require().NoError(err) - suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, app.AccountKeeper, multiPermAcc.GetName())) + suite.Require().Equal(sdk.Coins(nil), getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName())) suite.Require().Equal(initialSupply.GetTotal().Sub(initCoins), keeper.GetSupply(ctx).GetTotal()) } diff --git a/x/bank/types/account.go b/x/bank/types/account.go deleted file mode 100644 index 7dc8d91fc18e..000000000000 --- a/x/bank/types/account.go +++ /dev/null @@ -1,155 +0,0 @@ -package types - -import ( - "encoding/json" - "errors" - "fmt" - "strings" - - "github.com/tendermint/tendermint/crypto" - yaml "gopkg.in/yaml.v2" - - sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" -) - -var ( - _ authexported.GenesisAccount = (*ModuleAccount)(nil) - _ exported.ModuleAccountI = (*ModuleAccount)(nil) -) - -// NewModuleAddress creates an AccAddress from the hash of the module's name -func NewModuleAddress(name string) sdk.AccAddress { - return sdk.AccAddress(crypto.AddressHash([]byte(name))) -} - -// NewEmptyModuleAccount creates a empty ModuleAccount from a string -func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { - moduleAddress := NewModuleAddress(name) - baseAcc := authtypes.NewBaseAccountWithAddress(moduleAddress) - - if err := validatePermissions(permissions...); err != nil { - panic(err) - } - - return &ModuleAccount{ - BaseAccount: baseAcc, - Name: name, - Permissions: permissions, - } -} - -// NewModuleAccount creates a new ModuleAccount instance -func NewModuleAccount(ba *authtypes.BaseAccount, name string, permissions ...string) *ModuleAccount { - if err := validatePermissions(permissions...); err != nil { - panic(err) - } - - return &ModuleAccount{ - BaseAccount: ba, - Name: name, - Permissions: permissions, - } -} - -// HasPermission returns whether or not the module account has permission. -func (ma ModuleAccount) HasPermission(permission string) bool { - for _, perm := range ma.Permissions { - if perm == permission { - return true - } - } - return false -} - -// GetName returns the the name of the holder's module -func (ma ModuleAccount) GetName() string { - return ma.Name -} - -// GetPermissions returns permissions granted to the module account -func (ma ModuleAccount) GetPermissions() []string { - return ma.Permissions -} - -// SetPubKey - Implements Account -func (ma ModuleAccount) SetPubKey(pubKey crypto.PubKey) error { - return fmt.Errorf("not supported for module accounts") -} - -// SetSequence - Implements Account -func (ma ModuleAccount) SetSequence(seq uint64) error { - return fmt.Errorf("not supported for module accounts") -} - -// Validate checks for errors on the account fields -func (ma ModuleAccount) Validate() error { - if strings.TrimSpace(ma.Name) == "" { - return errors.New("module account name cannot be blank") - } - if !ma.Address.Equals(sdk.AccAddress(crypto.AddressHash([]byte(ma.Name)))) { - return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) - } - - return ma.BaseAccount.Validate() -} - -type moduleAccountPretty struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - PubKey string `json:"public_key" yaml:"public_key"` - AccountNumber uint64 `json:"account_number" yaml:"account_number"` - Sequence uint64 `json:"sequence" yaml:"sequence"` - Name string `json:"name" yaml:"name"` - Permissions []string `json:"permissions" yaml:"permissions"` -} - -func (ma ModuleAccount) String() string { - out, _ := ma.MarshalYAML() - return out.(string) -} - -// MarshalYAML returns the YAML representation of a ModuleAccount. -func (ma ModuleAccount) MarshalYAML() (interface{}, error) { - bs, err := yaml.Marshal(moduleAccountPretty{ - Address: ma.Address, - PubKey: "", - AccountNumber: ma.AccountNumber, - Sequence: ma.Sequence, - Name: ma.Name, - Permissions: ma.Permissions, - }) - - if err != nil { - return nil, err - } - - return string(bs), nil -} - -// MarshalJSON returns the JSON representation of a ModuleAccount. -func (ma ModuleAccount) MarshalJSON() ([]byte, error) { - return json.Marshal(moduleAccountPretty{ - Address: ma.Address, - PubKey: "", - AccountNumber: ma.AccountNumber, - Sequence: ma.Sequence, - Name: ma.Name, - Permissions: ma.Permissions, - }) -} - -// UnmarshalJSON unmarshals raw JSON bytes into a ModuleAccount. -func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error { - var alias moduleAccountPretty - if err := json.Unmarshal(bz, &alias); err != nil { - return err - } - - ma.BaseAccount = authtypes.NewBaseAccount(alias.Address, nil, alias.AccountNumber, alias.Sequence) - ma.Name = alias.Name - ma.Permissions = alias.Permissions - - return nil -} diff --git a/x/bank/types/account_test.go b/x/bank/types/account_test.go deleted file mode 100644 index a93fa5c94929..000000000000 --- a/x/bank/types/account_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package types - -import ( - "encoding/json" - "errors" - "fmt" - "testing" - - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" - yaml "gopkg.in/yaml.v2" - - sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -func TestModuleAccountMarshalYAML(t *testing.T) { - name := "test" - moduleAcc := NewEmptyModuleAccount(name, Minter, Burner, Staking) - bs, err := yaml.Marshal(moduleAcc) - require.NoError(t, err) - - want := "|\n address: cosmos1n7rdpqvgf37ktx30a2sv2kkszk3m7ncmg5drhe\n public_key: \"\"\n account_number: 0\n sequence: 0\n name: test\n permissions:\n - minter\n - burner\n - staking\n" - require.Equal(t, want, string(bs)) -} - -func TestHasPermissions(t *testing.T) { - name := "test" - macc := NewEmptyModuleAccount(name, Staking, Minter, Burner) - cases := []struct { - permission string - expectHas bool - }{ - {Staking, true}, - {Minter, true}, - {Burner, true}, - {"other", false}, - } - - for i, tc := range cases { - hasPerm := macc.HasPermission(tc.permission) - if tc.expectHas { - require.True(t, hasPerm, "test case #%d", i) - } else { - require.False(t, hasPerm, "test case #%d", i) - } - } -} - -func TestValidate(t *testing.T) { - addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - baseAcc := authtypes.NewBaseAccount(addr, nil, 0, 0) - tests := []struct { - name string - acc authexported.GenesisAccount - expErr error - }{ - { - "valid module account", - NewEmptyModuleAccount("test"), - nil, - }, - { - "invalid name and address pair", - NewModuleAccount(baseAcc, "test"), - fmt.Errorf("address %s cannot be derived from the module name 'test'", addr), - }, - { - "empty module account name", - NewModuleAccount(baseAcc, " "), - errors.New("module account name cannot be blank"), - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - err := tt.acc.Validate() - require.Equal(t, tt.expErr, err) - }) - } -} - -func TestModuleAccountJSON(t *testing.T) { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) - baseAcc := authtypes.NewBaseAccount(addr, nil, 10, 50) - acc := NewModuleAccount(baseAcc, "test", "burner") - - bz, err := json.Marshal(acc) - require.NoError(t, err) - - bz1, err := acc.MarshalJSON() - require.NoError(t, err) - require.Equal(t, string(bz1), string(bz)) - - var a ModuleAccount - require.NoError(t, json.Unmarshal(bz, &a)) - require.Equal(t, acc.String(), a.String()) -} diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index de20c60e83f9..bb2d0e306af0 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -20,9 +20,7 @@ type Codec interface { // RegisterCodec registers the necessary x/bank interfaces and concrete types // on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) cdc.RegisterInterface((*exported.SupplyI)(nil), nil) - cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) cdc.RegisterConcrete(&Supply{}, "cosmos-sdk/Supply", nil) cdc.RegisterConcrete(MsgSend{}, "cosmos-sdk/MsgSend", nil) cdc.RegisterConcrete(MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index 20caa3c57362..19a266354b5d 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -16,4 +16,12 @@ type AccountKeeper interface { SetAccount(ctx sdk.Context, acc exported.Account) IterateAccounts(ctx sdk.Context, process func(exported.Account) bool) + + ValidatePermissions(macc exported.ModuleAccountI) error + + GetModuleAddress(moduleName string) sdk.AccAddress + GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) + GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) + GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI + SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) } diff --git a/x/bank/types/types.pb.go b/x/bank/types/types.pb.go index 4aff7b421b0f..62a7f1df2ceb 100644 --- a/x/bank/types/types.pb.go +++ b/x/bank/types/types.pb.go @@ -8,7 +8,6 @@ import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" - types1 "github.com/cosmos/cosmos-sdk/x/auth/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -247,45 +246,6 @@ func (m *MsgMultiSend) GetOutputs() []Output { return nil } -// ModuleAccount defines an account for modules that holds coins on a pool -type ModuleAccount struct { - *types1.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty" yaml:"base_account"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty"` -} - -func (m *ModuleAccount) Reset() { *m = ModuleAccount{} } -func (*ModuleAccount) ProtoMessage() {} -func (*ModuleAccount) Descriptor() ([]byte, []int) { - return fileDescriptor_934ff6b24d3432e2, []int{4} -} -func (m *ModuleAccount) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ModuleAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ModuleAccount.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ModuleAccount) XXX_Merge(src proto.Message) { - xxx_messageInfo_ModuleAccount.Merge(m, src) -} -func (m *ModuleAccount) XXX_Size() int { - return m.Size() -} -func (m *ModuleAccount) XXX_DiscardUnknown() { - xxx_messageInfo_ModuleAccount.DiscardUnknown(m) -} - -var xxx_messageInfo_ModuleAccount proto.InternalMessageInfo - // Supply represents a struct that passively keeps track of the total supply // amounts in the network. type Supply struct { @@ -295,7 +255,7 @@ type Supply struct { func (m *Supply) Reset() { *m = Supply{} } func (*Supply) ProtoMessage() {} func (*Supply) Descriptor() ([]byte, []int) { - return fileDescriptor_934ff6b24d3432e2, []int{5} + return fileDescriptor_934ff6b24d3432e2, []int{4} } func (m *Supply) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -329,49 +289,42 @@ func init() { proto.RegisterType((*Input)(nil), "cosmos_sdk.x.bank.v1.Input") proto.RegisterType((*Output)(nil), "cosmos_sdk.x.bank.v1.Output") proto.RegisterType((*MsgMultiSend)(nil), "cosmos_sdk.x.bank.v1.MsgMultiSend") - proto.RegisterType((*ModuleAccount)(nil), "cosmos_sdk.x.bank.v1.ModuleAccount") proto.RegisterType((*Supply)(nil), "cosmos_sdk.x.bank.v1.Supply") } func init() { proto.RegisterFile("x/bank/types/types.proto", fileDescriptor_934ff6b24d3432e2) } var fileDescriptor_934ff6b24d3432e2 = []byte{ - // 549 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0xbf, 0x6f, 0xd3, 0x4c, - 0x18, 0xf6, 0xa5, 0x69, 0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x9c, 0x43, 0x32, 0x3f, 0xef, 0x01, 0xfc, 0x7f, 0x40, 0x9d, 0x78, 0xe6, 0xf6, 0x6d, 0x5b, - 0x1c, 0x0e, 0x44, 0x60, 0x63, 0x44, 0x98, 0x3b, 0x24, 0xe9, 0x5c, 0xc6, 0x5a, 0x3f, 0xba, 0x75, - 0x91, 0x5a, 0xf4, 0xa5, 0xa0, 0x36, 0x09, 0xcb, 0x81, 0xe6, 0xc1, 0x2a, 0xd1, 0xc0, 0xb6, 0xed, - 0x8a, 0x24, 0xba, 0x55, 0x1f, 0x6d, 0x77, 0x22, 0x04, 0xcb, 0x01, 0xf1, 0x5d, 0xd9, 0x3f, 0x35, - 0x4b, 0x8e, 0x51, 0x1b, 0xd6, 0x43, 0x37, 0xf2, 0x3d, 0xc6, 0x3c, 0x1a, 0x30, 0x79, 0xee, 0x6b, - 0x56, 0xf1, 0x53, 0xef, 0xbf, 0x57, 0x4b, 0x4d, 0x79, 0xbb, 0xd4, 0x14, 0x9d, 0xc1, 0xca, 0x49, - 0x1c, 0x86, 0xb3, 0x85, 0xa8, 0x18, 0xa7, 0x9c, 0xcc, 0xb2, 0xf0, 0xae, 0xab, 0x62, 0x92, 0xb3, - 0xd7, 0xc8, 0x05, 0x45, 0x52, 0xe6, 0xf1, 0xd9, 0x5a, 0x05, 0xab, 0xb5, 0x0a, 0xbe, 0xae, 0x55, - 0xf0, 0x66, 0xa3, 0x2a, 0xab, 0x8d, 0xaa, 0x7c, 0xde, 0xa8, 0xca, 0xb3, 0x3b, 0xbf, 0x24, 0x2e, - 0xde, 0x97, 0xa3, 0x8a, 0xbc, 0xbf, 0xee, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x55, 0x55, 0x67, - 0x85, 0x46, 0x05, 0x00, 0x00, + // 449 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xa8, 0xd0, 0x4f, 0x4a, + 0xcc, 0xcb, 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, + 0x42, 0x22, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x15, 0x7a, 0x20, + 0x45, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29, 0xf1, 0x05, 0x89, 0x45, 0x25, + 0x95, 0xfa, 0x60, 0x85, 0xfa, 0xe9, 0xf9, 0xe9, 0xf9, 0x08, 0x16, 0x44, 0xb7, 0x94, 0x20, 0x86, + 0x81, 0x4a, 0x87, 0x98, 0xb8, 0xd8, 0x7d, 0x8b, 0xd3, 0x83, 0x53, 0xf3, 0x52, 0x84, 0xb2, 0xb9, + 0x78, 0xd2, 0x8a, 0xf2, 0x73, 0xe3, 0x13, 0x53, 0x52, 0x8a, 0x52, 0x8b, 0x8b, 0x25, 0x18, 0x15, + 0x18, 0x35, 0x78, 0x9c, 0x3c, 0x3e, 0xdd, 0x93, 0x17, 0xae, 0x4c, 0xcc, 0xcd, 0xb1, 0x52, 0x42, + 0x96, 0x55, 0xfa, 0x75, 0x4f, 0x5e, 0x37, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, + 0x57, 0x1f, 0xe2, 0x30, 0x28, 0xa5, 0x5b, 0x9c, 0x02, 0x75, 0xbd, 0x9e, 0x63, 0x72, 0xb2, 0x23, + 0x44, 0x47, 0x10, 0x37, 0x48, 0x3f, 0x94, 0x23, 0x94, 0xca, 0xc5, 0x55, 0x92, 0x0f, 0xb7, 0x8a, + 0x09, 0x6c, 0x95, 0xdb, 0xa7, 0x7b, 0xf2, 0x82, 0x10, 0xab, 0x10, 0x72, 0x64, 0x58, 0xc4, 0x59, + 0x92, 0x0f, 0xb3, 0x26, 0x96, 0x8b, 0x2d, 0x31, 0x37, 0xbf, 0x34, 0xaf, 0x44, 0x82, 0x59, 0x81, + 0x59, 0x83, 0xdb, 0x48, 0x58, 0x0f, 0x29, 0x04, 0xcb, 0x0c, 0xf5, 0x9c, 0xf3, 0x33, 0xf3, 0x9c, + 0x0c, 0x4e, 0xdc, 0x93, 0x67, 0x58, 0x75, 0x5f, 0x5e, 0x83, 0x08, 0x6b, 0x40, 0x1a, 0x8a, 0x83, + 0xa0, 0x86, 0x5a, 0xb1, 0xbc, 0x58, 0x20, 0xcf, 0xa8, 0xb4, 0x9d, 0x91, 0x8b, 0xd5, 0x33, 0xaf, + 0xa0, 0xb4, 0x44, 0xc8, 0x9b, 0x8b, 0x1d, 0x35, 0xf4, 0x0c, 0x49, 0x77, 0x3d, 0xcc, 0x04, 0xa1, + 0x68, 0x2e, 0xd6, 0x64, 0x90, 0x6d, 0x12, 0x4c, 0xd4, 0x74, 0x3a, 0xc4, 0x4c, 0xa8, 0xcb, 0x77, + 0x30, 0x72, 0xb1, 0xf9, 0x97, 0x96, 0x0c, 0x45, 0xa7, 0xf7, 0x32, 0x72, 0xf1, 0xf8, 0x16, 0xa7, + 0xfb, 0x96, 0xe6, 0x94, 0x64, 0x82, 0x93, 0xaf, 0x25, 0x17, 0x5b, 0x26, 0x28, 0x12, 0x40, 0xee, + 0x07, 0x59, 0x2a, 0xad, 0x87, 0x2d, 0xb3, 0xe8, 0x81, 0x23, 0xca, 0x89, 0x05, 0x64, 0x79, 0x10, + 0x54, 0x83, 0x90, 0x0d, 0x17, 0x7b, 0x3e, 0x38, 0x14, 0x60, 0x0e, 0x96, 0xc1, 0xae, 0x17, 0x12, + 0x54, 0x50, 0xcd, 0x30, 0x2d, 0x50, 0xf7, 0x14, 0x73, 0xb1, 0x05, 0x97, 0x16, 0x14, 0xe4, 0x54, + 0x82, 0x3c, 0x5f, 0x92, 0x5f, 0x92, 0x98, 0x03, 0x75, 0x07, 0xb5, 0x3c, 0x0f, 0x36, 0xd3, 0x8a, + 0xa7, 0x63, 0x81, 0x3c, 0xc3, 0x8c, 0x05, 0xf2, 0x0c, 0x20, 0x4b, 0x9d, 0x9c, 0x4f, 0x3c, 0x92, + 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, + 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x13, 0xaf, 0xc1, 0xc8, 0x05, 0x4c, 0x12, 0x1b, + 0xb8, 0x28, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xd4, 0x0e, 0x1e, 0x07, 0x77, 0x04, 0x00, + 0x00, } func (this *MsgSend) Equal(that interface{}) bool { @@ -729,57 +682,6 @@ func (m *MsgMultiSend) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ModuleAccount) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ModuleAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Permissions) > 0 { - for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Permissions[iNdEx]) - copy(dAtA[i:], m.Permissions[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Permissions[iNdEx]))) - i-- - dAtA[i] = 0x1a - } - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0x12 - } - if m.BaseAccount != nil { - { - size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *Supply) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -910,29 +812,6 @@ func (m *MsgMultiSend) Size() (n int) { return n } -func (m *ModuleAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BaseAccount != nil { - l = m.BaseAccount.Size() - n += 1 + l + sovTypes(uint64(l)) - } - l = len(m.Name) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - if len(m.Permissions) > 0 { - for _, s := range m.Permissions { - l = len(s) - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - func (m *Supply) Size() (n int) { if m == nil { return 0 @@ -1472,159 +1351,6 @@ func (m *MsgMultiSend) Unmarshal(dAtA []byte) error { } return nil } -func (m *ModuleAccount) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ModuleAccount: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ModuleAccount: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.BaseAccount == nil { - m.BaseAccount = &types1.BaseAccount{} - } - if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *Supply) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/bank/types/types.proto b/x/bank/types/types.proto index 699b34afd58b..a1cbd9f61275 100644 --- a/x/bank/types/types.proto +++ b/x/bank/types/types.proto @@ -3,7 +3,6 @@ package cosmos_sdk.x.bank.v1; import "third_party/proto/gogoproto/gogo.proto"; import "types/types.proto"; -import "x/auth/types/types.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types"; @@ -49,17 +48,6 @@ message MsgMultiSend { repeated Output outputs = 2 [(gogoproto.nullable) = false]; } -// ModuleAccount defines an account for modules that holds coins on a pool -message ModuleAccount { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - - cosmos_sdk.x.auth.v1.BaseAccount base_account = 1 - [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; - string name = 2; - repeated string permissions = 3; -} - // Supply represents a struct that passively keeps track of the total supply // amounts in the network. message Supply { diff --git a/x/distribution/genesis.go b/x/distribution/genesis.go index db66057fd86a..70092f3cc04c 100644 --- a/x/distribution/genesis.go +++ b/x/distribution/genesis.go @@ -8,7 +8,7 @@ import ( ) // InitGenesis sets distribution information for genesis -func InitGenesis(ctx sdk.Context, bk types.BankKeeper, keeper Keeper, data types.GenesisState) { +func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, keeper Keeper, data types.GenesisState) { var moduleHoldings sdk.DecCoins keeper.SetFeePool(ctx, data.FeePool) @@ -52,7 +52,7 @@ func InitGenesis(ctx sdk.Context, bk types.BankKeeper, keeper Keeper, data types panic(err) } - bk.SetModuleAccount(ctx, moduleAcc) + ak.SetModuleAccount(ctx, moduleAcc) } } diff --git a/x/distribution/keeper/alias_functions.go b/x/distribution/keeper/alias_functions.go index e0a1d2bf638b..29406e326c06 100644 --- a/x/distribution/keeper/alias_functions.go +++ b/x/distribution/keeper/alias_functions.go @@ -2,7 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -17,6 +17,6 @@ func (k Keeper) GetFeePoolCommunityCoins(ctx sdk.Context) sdk.DecCoins { } // GetDistributionAccount returns the distribution ModuleAccount -func (k Keeper) GetDistributionAccount(ctx sdk.Context) exported.ModuleAccountI { - return k.bankKeeper.GetModuleAccount(ctx, types.ModuleName) +func (k Keeper) GetDistributionAccount(ctx sdk.Context) authexported.ModuleAccountI { + return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) } diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 423c99c80fdf..593d02d04d34 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -21,7 +21,7 @@ func (k Keeper) AllocateTokens( // fetch and clear the collected fees for distribution, since this is // called in BeginBlock, collected fees will be from the previous block // (and distributed to the previous proposer) - feeCollector := k.bankKeeper.GetModuleAccount(ctx, k.feeCollectorName) + feeCollector := k.authKeeper.GetModuleAccount(ctx, k.feeCollectorName) feesCollectedInt := k.bankKeeper.GetAllBalances(ctx, feeCollector.GetAddress()) feesCollected := sdk.NewDecCoinsFromCoins(feesCollectedInt...) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index d3f4223fd703..93df14c37cd8 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -97,7 +97,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { // allocate tokens as if both had voted and second was proposer fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))) - feeCollector := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName) + feeCollector := app.AccountKeeper.GetModuleAccount(ctx, types.FeeCollectorName) require.NotNil(t, feeCollector) err = app.BankKeeper.SetBalances(ctx, feeCollector.GetAddress(), fees) @@ -189,7 +189,7 @@ func TestAllocateTokensTruncation(t *testing.T) { // allocate tokens as if both had voted and second was proposer fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(634195840))) - feeCollector := app.BankKeeper.GetModuleAccount(ctx, types.FeeCollectorName) + feeCollector := app.AccountKeeper.GetModuleAccount(ctx, types.FeeCollectorName) require.NotNil(t, feeCollector) err = app.BankKeeper.SetBalances(ctx, feeCollector.GetAddress(), fees) diff --git a/x/distribution/keeper/common_test.go b/x/distribution/keeper/common_test.go index 9a17225ea791..655082cc426e 100644 --- a/x/distribution/keeper/common_test.go +++ b/x/distribution/keeper/common_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -17,5 +17,5 @@ var ( valConsAddr1 = sdk.ConsAddress(valConsPk1.Address()) valConsAddr2 = sdk.ConsAddress(valConsPk2.Address()) - distrAcc = bank.NewEmptyModuleAccount(types.ModuleName) + distrAcc = auth.NewEmptyModuleAccount(types.ModuleName) ) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 00f6a3da8c63..4ff953ea03f6 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -312,7 +312,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { // set module account coins distrAcc := app.DistrKeeper.GetDistributionAccount(ctx) require.NoError(t, app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, balanceTokens)))) - app.BankKeeper.SetModuleAccount(ctx, distrAcc) + app.AccountKeeper.SetModuleAccount(ctx, distrAcc) // create validator with 50% commission power := int64(100) @@ -555,7 +555,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { distrAcc := app.DistrKeeper.GetDistributionAccount(ctx) err := app.BankKeeper.SetBalances(ctx, distrAcc.GetAddress(), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, distrAcc) + app.AccountKeeper.SetModuleAccount(ctx, distrAcc) tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))} diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 96543955676a..5d1981a8ad56 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -17,6 +17,7 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.Marshaler paramSpace paramtypes.Subspace + authKeeper types.AccountKeeper bankKeeper types.BankKeeper stakingKeeper types.StakingKeeper @@ -27,12 +28,13 @@ type Keeper struct { // NewKeeper creates a new distribution Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, bk types.BankKeeper, - sk types.StakingKeeper, feeCollectorName string, blacklistedAddrs map[string]bool, + cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, + ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, + feeCollectorName string, blacklistedAddrs map[string]bool, ) Keeper { // ensure distribution module account is set - if addr := bk.GetModuleAddress(types.ModuleName); addr == nil { + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } @@ -45,6 +47,7 @@ func NewKeeper( storeKey: key, cdc: cdc, paramSpace: paramSpace, + authKeeper: ak, bankKeeper: bk, stakingKeeper: sk, feeCollectorName: feeCollectorName, diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 73274842ff03..4829bd33be5e 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -54,7 +54,7 @@ func TestWithdrawValidatorCommission(t *testing.T) { sdk.NewCoin("stake", sdk.NewInt(2)), )) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, distrAcc) + app.AccountKeeper.SetModuleAccount(ctx, distrAcc) // check initial balance balance := app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(valAddrs[0])) diff --git a/x/distribution/module.go b/x/distribution/module.go index 14f721eeda5b..8f3eb7ac0c0d 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -132,7 +132,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.bankKeeper, am.keeper, genesisState) + InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/distribution/module_test.go b/x/distribution/module_test.go index f22c3ad769ac..7095ce859014 100644 --- a/x/distribution/module_test.go +++ b/x/distribution/module_test.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/distribution" ) @@ -22,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { }, ) - acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(distribution.ModuleName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(distribution.ModuleName)) require.NotNil(t, acc) } diff --git a/x/distribution/proposal_handler_test.go b/x/distribution/proposal_handler_test.go index cf6b1a6125ac..d8b21928b8c4 100644 --- a/x/distribution/proposal_handler_test.go +++ b/x/distribution/proposal_handler_test.go @@ -36,7 +36,7 @@ func TestProposalHandlerPassed(t *testing.T) { err := app.BankKeeper.SetBalances(ctx, macc.GetAddress(), balances.Add(amount...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, macc) + app.AccountKeeper.SetModuleAccount(ctx, macc) account := app.AccountKeeper.NewAccountWithAddress(ctx, recipient) app.AccountKeeper.SetAccount(ctx, account) diff --git a/x/distribution/types/expected_keepers.go b/x/distribution/types/expected_keepers.go index 348e59c20286..4e39b3ff3376 100644 --- a/x/distribution/types/expected_keepers.go +++ b/x/distribution/types/expected_keepers.go @@ -3,7 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" "github.com/cosmos/cosmos-sdk/x/staking" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -11,6 +10,12 @@ import ( // AccountKeeper defines the expected account keeper used for simulations (noalias) type AccountKeeper interface { GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI + + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(sdk.Context, authexported.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances. @@ -21,12 +26,6 @@ type BankKeeper interface { LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI - - // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, bankexported.ModuleAccountI) - SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 870f80fb4fd5..896b71446ee0 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -8,7 +8,7 @@ import ( ) // InitGenesis - store genesis parameters -func InitGenesis(ctx sdk.Context, bk types.BankKeeper, k Keeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k Keeper, data GenesisState) { k.SetProposalID(ctx, data.StartingProposalID) k.SetDepositParams(ctx, data.DepositParams) k.SetVotingParams(ctx, data.VotingParams) @@ -46,7 +46,7 @@ func InitGenesis(ctx sdk.Context, bk types.BankKeeper, k Keeper, data GenesisSta panic(err) } - bk.SetModuleAccount(ctx, moduleAcc) + ak.SetModuleAccount(ctx, moduleAcc) } } diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 786465a65844..90b645b79a99 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -21,6 +21,7 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd app.StakingKeeper = staking.NewKeeper( appCodec, app.GetKey(staking.StoreKey), + app.AccountKeeper, app.BankKeeper, app.GetSubspace(staking.ModuleName), ) diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index 69d0e8cf489a..04795c70f67c 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/libs/log" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -16,6 +16,7 @@ type Keeper struct { // The reference to the Paramstore to get and set gov specific params paramSpace types.ParamSubspace + authKeeper types.AccountKeeper bankKeeper types.BankKeeper // The reference to the DelegationSet and ValidatorSet to get information about validators and delegators @@ -40,11 +41,11 @@ type Keeper struct { // CONTRACT: the parameter Subspace must have the param key table already initialized func NewKeeper( cdc types.Codec, key sdk.StoreKey, paramSpace types.ParamSubspace, - bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr types.Router, + authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, rtr types.Router, ) Keeper { // ensure governance module account is set - if addr := bankKeeper.GetModuleAddress(types.ModuleName); addr == nil { + if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } @@ -56,6 +57,7 @@ func NewKeeper( return Keeper{ storeKey: key, paramSpace: paramSpace, + authKeeper: authKeeper, bankKeeper: bankKeeper, sk: sk, cdc: cdc, @@ -74,8 +76,8 @@ func (keeper Keeper) Router() types.Router { } // GetGovernanceAccount returns the governance ModuleAccount -func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) exported.ModuleAccountI { - return keeper.bankKeeper.GetModuleAccount(ctx, types.ModuleName) +func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) authexported.ModuleAccountI { + return keeper.authKeeper.GetModuleAccount(ctx, types.ModuleName) } // ProposalQueues diff --git a/x/gov/module.go b/x/gov/module.go index 7574c3dcde01..4b53a38edad9 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -150,7 +150,7 @@ func (am AppModule) NewQuerierHandler() sdk.Querier { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.bankKeeper, am.keeper, genesisState) + InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/gov/module_test.go b/x/gov/module_test.go index f55a95461385..cb8446e31747 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" ) @@ -22,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { }, ) - acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(gov.ModuleName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(gov.ModuleName)) require.NotNil(t, acc) } diff --git a/x/gov/types/expected_keepers.go b/x/gov/types/expected_keepers.go index 5363287b8783..2ff31a2612d9 100644 --- a/x/gov/types/expected_keepers.go +++ b/x/gov/types/expected_keepers.go @@ -3,7 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" - bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -30,6 +29,12 @@ type StakingKeeper interface { // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI + + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(sdk.Context, authexported.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances. @@ -40,12 +45,6 @@ type BankKeeper interface { LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins - GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI - - // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, bankexported.ModuleAccountI) - SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error diff --git a/x/ibc/20-transfer/keeper/keeper.go b/x/ibc/20-transfer/keeper/keeper.go index 6621f1e3f977..814570d81d08 100644 --- a/x/ibc/20-transfer/keeper/keeper.go +++ b/x/ibc/20-transfer/keeper/keeper.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/capability" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" @@ -29,6 +29,7 @@ type Keeper struct { channelKeeper types.ChannelKeeper portKeeper types.PortKeeper + authKeeper types.AccountKeeper bankKeeper types.BankKeeper scopedKeeper capability.ScopedKeeper } @@ -37,11 +38,11 @@ type Keeper struct { func NewKeeper( cdc *codec.Codec, key sdk.StoreKey, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, - bankKeeper types.BankKeeper, scopedKeeper capability.ScopedKeeper, + authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, scopedKeeper capability.ScopedKeeper, ) Keeper { // ensure ibc transfer module account is set - if addr := bankKeeper.GetModuleAddress(types.GetModuleAccountName()); addr == nil { + if addr := authKeeper.GetModuleAddress(types.GetModuleAccountName()); addr == nil { panic("the IBC transfer module account has not been set") } @@ -50,6 +51,7 @@ func NewKeeper( cdc: cdc, channelKeeper: channelKeeper, portKeeper: portKeeper, + authKeeper: authKeeper, bankKeeper: bankKeeper, scopedKeeper: scopedKeeper, } @@ -61,8 +63,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // GetTransferAccount returns the ICS20 - transfers ModuleAccount -func (k Keeper) GetTransferAccount(ctx sdk.Context) bankexported.ModuleAccountI { - return k.bankKeeper.GetModuleAccount(ctx, types.GetModuleAccountName()) +func (k Keeper) GetTransferAccount(ctx sdk.Context) authexported.ModuleAccountI { + return k.authKeeper.GetModuleAccount(ctx, types.GetModuleAccountName()) } // PacketExecuted defines a wrapper function for the channel Keeper's function diff --git a/x/ibc/20-transfer/types/expected_keepers.go b/x/ibc/20-transfer/types/expected_keepers.go index 7d675c54d491..1bb41ea225bd 100644 --- a/x/ibc/20-transfer/types/expected_keepers.go +++ b/x/ibc/20-transfer/types/expected_keepers.go @@ -2,7 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/capability" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" @@ -10,12 +10,15 @@ import ( channelexported "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" ) +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI +} + // BankKeeper defines the expected bank keeper type BankKeeper interface { SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error - - GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) bankexported.ModuleAccountI MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error diff --git a/x/mint/genesis.go b/x/mint/genesis.go index d2e3f65cdf24..442646efd79c 100644 --- a/x/mint/genesis.go +++ b/x/mint/genesis.go @@ -6,10 +6,10 @@ import ( ) // InitGenesis new mint genesis -func InitGenesis(ctx sdk.Context, keeper Keeper, bankKeeper types.BankKeeper, data GenesisState) { +func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data GenesisState) { keeper.SetMinter(ctx, data.Minter) keeper.SetParams(ctx, data.Params) - bankKeeper.GetModuleAccount(ctx, ModuleName) + ak.GetModuleAccount(ctx, ModuleName) } // ExportGenesis returns a GenesisState for a given context and keeper. diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index 16113152aece..597c1b520b94 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -16,7 +16,7 @@ type Keeper struct { cdc codec.Marshaler storeKey sdk.StoreKey paramSpace paramtypes.Subspace - sk types.StakingKeeper + stakingKeeper types.StakingKeeper bankKeeper types.BankKeeper feeCollectorName string } @@ -24,11 +24,12 @@ type Keeper struct { // NewKeeper creates a new mint Keeper instance func NewKeeper( cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, - sk types.StakingKeeper, bankKeeper types.BankKeeper, feeCollectorName string, + sk types.StakingKeeper, ak types.AccountKeeper, bk types.BankKeeper, + feeCollectorName string, ) Keeper { // ensure mint module account is set - if addr := bankKeeper.GetModuleAddress(types.ModuleName); addr == nil { + if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { panic("the mint module account has not been set") } @@ -41,8 +42,8 @@ func NewKeeper( cdc: cdc, storeKey: key, paramSpace: paramSpace, - sk: sk, - bankKeeper: bankKeeper, + stakingKeeper: sk, + bankKeeper: bk, feeCollectorName: feeCollectorName, } } @@ -91,13 +92,13 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { // StakingTokenSupply implements an alias call to the underlying staking keeper's // StakingTokenSupply to be used in BeginBlocker. func (k Keeper) StakingTokenSupply(ctx sdk.Context) sdk.Int { - return k.sk.StakingTokenSupply(ctx) + return k.stakingKeeper.StakingTokenSupply(ctx) } // BondedRatio implements an alias call to the underlying staking keeper's // BondedRatio to be used in BeginBlocker. func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec { - return k.sk.BondedRatio(ctx) + return k.stakingKeeper.BondedRatio(ctx) } // MintCoins implements an alias call to the underlying supply keeper's diff --git a/x/mint/module.go b/x/mint/module.go index f546856c465c..b3aba891af3c 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -75,15 +75,15 @@ type AppModule struct { AppModuleBasic keeper Keeper - bankKeeper types.BankKeeper + authKeeper types.AccountKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(keeper Keeper, bankKeeper types.BankKeeper) AppModule { +func NewAppModule(keeper Keeper, ak types.AccountKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, - bankKeeper: bankKeeper, + authKeeper: ak, } } @@ -117,7 +117,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j var genesisState GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.keeper, am.bankKeeper, genesisState) + InitGenesis(ctx, am.keeper, am.authKeeper, genesisState) return []abci.ValidatorUpdate{} } diff --git a/x/mint/module_test.go b/x/mint/module_test.go index b3c6fd42decb..a12986468e27 100644 --- a/x/mint/module_test.go +++ b/x/mint/module_test.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/mint" ) @@ -22,6 +22,6 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { }, ) - acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(mint.ModuleName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(mint.ModuleName)) require.NotNil(t, acc) } diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go index 0e5372259dfe..542b293258b8 100644 --- a/x/mint/types/expected_keepers.go +++ b/x/mint/types/expected_keepers.go @@ -2,7 +2,7 @@ package types // noalias import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // StakingKeeper defines the expected staking keeper @@ -11,15 +11,18 @@ type StakingKeeper interface { BondedRatio(ctx sdk.Context) sdk.Dec } -// BankKeeper defines the contract needed to be fulfilled for banking and supply -// dependencies. -type BankKeeper interface { +// AccountKeeper defines the contract required for account APIs. +type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, exported.ModuleAccountI) - GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI + SetModuleAccount(sdk.Context, authexported.ModuleAccountI) + GetModuleAccount(ctx sdk.Context, moduleName string) authexported.ModuleAccountI +} +// BankKeeper defines the contract needed to be fulfilled for banking and supply +// dependencies. +type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error diff --git a/x/staking/common_test.go b/x/staking/common_test.go index 216f924fa357..85bec932f837 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -48,6 +48,7 @@ func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) app.StakingKeeper = keeper.NewKeeper( appCodec, app.GetKey(staking.StoreKey), + app.AccountKeeper, app.BankKeeper, app.GetSubspace(staking.ModuleName), ) diff --git a/x/staking/genesis.go b/x/staking/genesis.go index c34e77f00756..05ac9397c9c0 100644 --- a/x/staking/genesis.go +++ b/x/staking/genesis.go @@ -105,7 +105,7 @@ func InitGenesis( panic(err) } - bankKeeper.SetModuleAccount(ctx, bondedPool) + accountKeeper.SetModuleAccount(ctx, bondedPool) } notBondedPool := keeper.GetNotBondedPool(ctx) @@ -118,7 +118,7 @@ func InitGenesis( panic(err) } - bankKeeper.SetModuleAccount(ctx, notBondedPool) + accountKeeper.SetModuleAccount(ctx, notBondedPool) } // don't need to run Tendermint updates if we exported diff --git a/x/staking/genesis_test.go b/x/staking/genesis_test.go index b9ee442f82aa..71a00bf92a4f 100644 --- a/x/staking/genesis_test.go +++ b/x/staking/genesis_test.go @@ -28,7 +28,7 @@ func bootstrapGenesisTest(t *testing.T, power int64, numAddrs int) (*simapp.SimA err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply)) return app, ctx, addrDels, addrVals diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 84ccc2fcb396..99fa87a3df45 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -33,7 +33,7 @@ func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmo err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply)) return app, ctx, addrDels, addrVals diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index 744eb41f439e..579dc4afb99c 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -29,6 +29,7 @@ func createTestInput() (*codec.Codec, *simapp.SimApp, sdk.Context) { app.StakingKeeper = keeper.NewKeeper( appCodec, app.GetKey(staking.StoreKey), + app.AccountKeeper, app.BankKeeper, app.GetSubspace(staking.ModuleName), ) diff --git a/x/staking/keeper/delegation_test.go b/x/staking/keeper/delegation_test.go index acd4ffced0fe..8eaee5709bc8 100644 --- a/x/staking/keeper/delegation_test.go +++ b/x/staking/keeper/delegation_test.go @@ -192,7 +192,7 @@ func TestUnbondDelegation(t *testing.T) { sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), startTokens)), ), ) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator and a delegator to that validator // note this validator starts not-bonded @@ -234,7 +234,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) { err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator and a delegator to that validator validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -324,7 +324,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) require.True(t, validator.IsBonded()) @@ -337,7 +337,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // create a second delegation to this validator app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator) @@ -349,7 +349,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) { oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) delegation := types.NewDelegation(addrDels[0], addrVals[0], issuedShares) @@ -389,7 +389,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) require.True(t, validator.IsBonded()) @@ -401,7 +401,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // create a second delegation to this validator app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator) @@ -412,7 +412,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) delegation := types.NewDelegation(addrDels[1], addrVals[0], issuedShares) @@ -421,7 +421,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) { oldBonded = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) header := ctx.BlockHeader() blockHeight := int64(10) @@ -476,7 +476,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -495,7 +495,7 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) { oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // create a second delegation to this validator app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator) @@ -560,7 +560,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) //create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -585,7 +585,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) { oldBonded := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), oldBonded.Add(delCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validator = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validator, true) require.True(t, validator.IsBonded()) @@ -727,7 +727,7 @@ func TestRedelegateToSameValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -758,7 +758,7 @@ func TestRedelegationMaxEntries(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -816,7 +816,7 @@ func TestRedelegateSelfDelegation(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) //create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -873,7 +873,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) //create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -957,7 +957,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) { oldNotBonded := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), oldNotBonded.Add(startCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) //create a validator with a self-delegation validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 3d623863a5c3..14d9e9a23222 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -24,6 +24,7 @@ var _ types.DelegationSet = Keeper{} type Keeper struct { storeKey sdk.StoreKey cdc codec.Marshaler + authKeeper types.AccountKeeper bankKeeper types.BankKeeper hooks types.StakingHooks paramstore paramtypes.Subspace @@ -33,7 +34,8 @@ type Keeper struct { // NewKeeper creates a new staking Keeper instance func NewKeeper( - cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, ps paramtypes.Subspace, + cdc codec.Marshaler, key sdk.StoreKey, ak types.AccountKeeper, bk types.BankKeeper, + ps paramtypes.Subspace, ) Keeper { // set KeyTable if it has not already been set @@ -42,17 +44,18 @@ func NewKeeper( } // ensure bonded and not bonded module accounts are set - if addr := bk.GetModuleAddress(types.BondedPoolName); addr == nil { + if addr := ak.GetModuleAddress(types.BondedPoolName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.BondedPoolName)) } - if addr := bk.GetModuleAddress(types.NotBondedPoolName); addr == nil { + if addr := ak.GetModuleAddress(types.NotBondedPoolName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName)) } return Keeper{ storeKey: key, cdc: cdc, + authKeeper: ak, bankKeeper: bk, paramstore: ps, hooks: nil, diff --git a/x/staking/keeper/pool.go b/x/staking/keeper/pool.go index b395dae25586..43421ae7f026 100644 --- a/x/staking/keeper/pool.go +++ b/x/staking/keeper/pool.go @@ -2,18 +2,18 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/exported" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/staking/types" ) // GetBondedPool returns the bonded tokens pool's module account -func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool exported.ModuleAccountI) { - return k.bankKeeper.GetModuleAccount(ctx, types.BondedPoolName) +func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool authexported.ModuleAccountI) { + return k.authKeeper.GetModuleAccount(ctx, types.BondedPoolName) } // GetNotBondedPool returns the not bonded tokens pool's module account -func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool exported.ModuleAccountI) { - return k.bankKeeper.GetModuleAccount(ctx, types.NotBondedPoolName) +func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool authexported.ModuleAccountI) { + return k.authKeeper.GetModuleAccount(ctx, types.NotBondedPoolName) } // bondedTokensToNotBonded transfers coins from the bonded to the not bonded pool within staking diff --git a/x/staking/keeper/slash_test.go b/x/staking/keeper/slash_test.go index d7be53da20ee..9aa9e751fe7a 100644 --- a/x/staking/keeper/slash_test.go +++ b/x/staking/keeper/slash_test.go @@ -28,7 +28,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) numVals := int64(3) bondedCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), amt.MulRaw(numVals))) @@ -37,7 +37,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, err = app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), bondedCoins) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply)) for i := int64(0); i < numVals; i++ { @@ -129,7 +129,7 @@ func TestSlashRedelegation(t *testing.T) { balances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), balances.Add(startCoins...))) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // set a redelegation with an expiration timestamp beyond which the // redelegation shouldn't be slashed @@ -416,7 +416,7 @@ func TestSlashWithRedelegation(t *testing.T) { err := app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), balances.Add(rdCoins...)) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) oldBonded := app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount oldNotBonded := app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount @@ -583,8 +583,8 @@ func TestSlashBoth(t *testing.T) { notBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), notBondedPoolBalances.Add(notBondedCoins...))) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) oldBonded := app.BankKeeper.GetBalance(ctx, bondedPool.GetAddress(), bondDenom).Amount oldNotBonded := app.BankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom).Amount diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index ad36117c03ba..d532a4ee173d 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -28,7 +28,7 @@ func bootstrapValidatorTest(t *testing.T, power int64, numAddrs int) (*simapp.Si err := app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), totalSupply) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) app.BankKeeper.SetSupply(ctx, bank.NewSupply(totalSupply)) return app, ctx, addrDels, addrVals @@ -100,8 +100,8 @@ func TestUpdateValidatorByPowerIndex(t *testing.T) { err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000)))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // add a validator validator := types.NewValidator(addrVals[0], PKs[0], types.Description{}) @@ -152,8 +152,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) { err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(10000)))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators := make([]types.Validator, numVals) for i := 0; i < len(validators); i++ { @@ -205,7 +205,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) { err := app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validator, _ = validator.AddTokensFromDel(valTokens) require.Equal(t, sdk.Unbonded, validator.Status) @@ -414,8 +414,8 @@ func TestGetValidatorSortingMixed(t *testing.T) { err = app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), sdk.TokensFromConsensusPower(0)))) require.NoError(t, err) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) // now 2 max resValidators params := app.StakingKeeper.GetParams(ctx) @@ -489,7 +489,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { balances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), balances.Add(sdk.NewCoin(params.BondDenom, tokens)))) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true) } @@ -509,7 +509,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { balances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), balances.Add(newTokens...))) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) // test that the two largest validators are // a) validator 0 with 500 tokens @@ -542,7 +542,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { newTokens = sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.TokensFromConsensusPower(1))) balances = app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), balances.Add(newTokens...))) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) resValidators = app.StakingKeeper.GetBondedValidatorsByPower(ctx) @@ -558,7 +558,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { bondedPool := app.StakingKeeper.GetBondedPool(ctx) balances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, bondedPool.GetAddress(), balances.Add(sdk.NewCoin(params.BondDenom, rmTokens)))) - app.BankKeeper.SetModuleAccount(ctx, bondedPool) + app.AccountKeeper.SetModuleAccount(ctx, bondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) resValidators = app.StakingKeeper.GetBondedValidatorsByPower(ctx) @@ -573,7 +573,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) { notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx) balances = app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()) require.NoError(t, app.BankKeeper.SetBalances(ctx, notBondedPool.GetAddress(), balances.Add(sdk.NewCoin(params.BondDenom, sdk.NewInt(200))))) - app.BankKeeper.SetModuleAccount(ctx, notBondedPool) + app.AccountKeeper.SetModuleAccount(ctx, notBondedPool) validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true) resValidators = app.StakingKeeper.GetBondedValidatorsByPower(ctx) diff --git a/x/staking/module_test.go b/x/staking/module_test.go index 51cfbccaeb48..de77f4c97f8f 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -22,9 +22,9 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { }, ) - acc := app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(staking.BondedPoolName)) + acc := app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(staking.BondedPoolName)) require.NotNil(t, acc) - acc = app.AccountKeeper.GetAccount(ctx, bank.NewModuleAddress(staking.NotBondedPoolName)) + acc = app.AccountKeeper.GetAccount(ctx, auth.NewModuleAddress(staking.NotBondedPoolName)) require.NotNil(t, acc) } diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 99031ee3ba88..e0f58b86cb4e 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -17,6 +17,12 @@ type DistributionKeeper interface { type AccountKeeper interface { IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool)) GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account // only used for simulation + + GetModuleAddress(name string) sdk.AccAddress + GetModuleAccount(ctx sdk.Context, moduleName string) authexported.ModuleAccountI + + // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 + SetModuleAccount(sdk.Context, authexported.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances. @@ -29,12 +35,6 @@ type BankKeeper interface { GetSupply(ctx sdk.Context) bankexported.SupplyI - GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, moduleName string) bankexported.ModuleAccountI - - // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, bankexported.ModuleAccountI) - SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error