From 80a53dc3e09642effc4e60d5ba751109e16b650e Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Thu, 19 Jan 2023 15:12:49 +0900 Subject: [PATCH 1/3] Get rid of account keeper from x/token --- simapp/app.go | 2 +- x/token/expected_keepers.go | 9 --------- x/token/keeper/keeper.go | 11 ++++------- x/token/keeper/send.go | 8 -------- x/token/keeper/supply.go | 4 ---- 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index b50131bfd2..2da62f882c 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -314,7 +314,7 @@ func NewSimApp( app.FoundationKeeper = foundationkeeper.NewKeeper(appCodec, keys[foundation.StoreKey], app.BaseApp.MsgServiceRouter(), app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, foundationConfig, foundation.DefaultAuthority().String()) classKeeper := classkeeper.NewKeeper(appCodec, keys[class.StoreKey]) - app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.AccountKeeper, classKeeper) + app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], classKeeper) app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], app.AccountKeeper, classKeeper) // register the staking hooks diff --git a/x/token/expected_keepers.go b/x/token/expected_keepers.go index b016098ada..bc85027126 100644 --- a/x/token/expected_keepers.go +++ b/x/token/expected_keepers.go @@ -2,18 +2,9 @@ package token import ( sdk "github.com/line/lbm-sdk/types" - authtypes "github.com/line/lbm-sdk/x/auth/types" ) type ( - // AccountKeeper defines the contract required for account APIs. - AccountKeeper interface { - HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool - SetAccount(ctx sdk.Context, account authtypes.AccountI) - - NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - } - // ClassKeeper defines the contract needed to be fulfilled for class dependencies. ClassKeeper interface { NewID(ctx sdk.Context) string diff --git a/x/token/keeper/keeper.go b/x/token/keeper/keeper.go index 446447f1a9..9bea2853b2 100644 --- a/x/token/keeper/keeper.go +++ b/x/token/keeper/keeper.go @@ -8,8 +8,7 @@ import ( // Keeper defines the token module Keeper type Keeper struct { - accountKeeper token.AccountKeeper - classKeeper token.ClassKeeper + classKeeper token.ClassKeeper // The (unexposed) keys used to access the stores from the Context. storeKey sdk.StoreKey @@ -22,13 +21,11 @@ type Keeper struct { func NewKeeper( cdc codec.Codec, key sdk.StoreKey, - ak token.AccountKeeper, ck token.ClassKeeper, ) Keeper { return Keeper{ - accountKeeper: ak, - classKeeper: ck, - storeKey: key, - cdc: cdc, + classKeeper: ck, + storeKey: key, + cdc: cdc, } } diff --git a/x/token/keeper/send.go b/x/token/keeper/send.go index de76b8c361..69cd6f5951 100644 --- a/x/token/keeper/send.go +++ b/x/token/keeper/send.go @@ -29,10 +29,6 @@ func (k Keeper) AuthorizeOperator(ctx sdk.Context, contractID string, holder, op k.setAuthorization(ctx, contractID, holder, operator) - if !k.accountKeeper.HasAccount(ctx, operator) { - k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, operator)) - } - return nil } @@ -88,10 +84,6 @@ func (k Keeper) addToken(ctx sdk.Context, contractID string, addr sdk.AccAddress newBalance := balance.Add(amount) k.setBalance(ctx, contractID, addr, newBalance) - - if !k.accountKeeper.HasAccount(ctx, addr) { - k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, addr)) - } } func (k Keeper) GetBalance(ctx sdk.Context, contractID string, addr sdk.AccAddress) sdk.Int { diff --git a/x/token/keeper/supply.go b/x/token/keeper/supply.go index 328c1a8b60..532b6064d6 100644 --- a/x/token/keeper/supply.go +++ b/x/token/keeper/supply.go @@ -323,10 +323,6 @@ func (k Keeper) Grant(ctx sdk.Context, contractID string, granter, grantee sdk.A func (k Keeper) grant(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission token.Permission) { k.setGrant(ctx, contractID, grantee, permission) - - if !k.accountKeeper.HasAccount(ctx, grantee) { - k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, grantee)) - } } func (k Keeper) Abandon(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission token.Permission) { From b242b836c4be8f0f371b3f5ec43f2af38980d6cf Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Thu, 19 Jan 2023 16:03:54 +0900 Subject: [PATCH 2/3] Get rid of account keeper from x/collection --- simapp/app.go | 2 +- x/collection/expected_keepers.go | 9 --------- x/collection/keeper/keeper.go | 19 ++++--------------- x/collection/keeper/send.go | 6 ------ x/collection/keeper/supply.go | 3 --- x/collection/msgs_test.go | 2 +- 6 files changed, 6 insertions(+), 35 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 2da62f882c..74117d7e06 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -315,7 +315,7 @@ func NewSimApp( classKeeper := classkeeper.NewKeeper(appCodec, keys[class.StoreKey]) app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], classKeeper) - app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], app.AccountKeeper, classKeeper) + app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], classKeeper) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks diff --git a/x/collection/expected_keepers.go b/x/collection/expected_keepers.go index 458b1e7bdf..3de4c66e52 100644 --- a/x/collection/expected_keepers.go +++ b/x/collection/expected_keepers.go @@ -2,18 +2,9 @@ package collection import ( sdk "github.com/line/lbm-sdk/types" - authtypes "github.com/line/lbm-sdk/x/auth/types" ) type ( - // AccountKeeper defines the contract required for account APIs. - AccountKeeper interface { - HasAccount(ctx sdk.Context, addr sdk.AccAddress) bool - SetAccount(ctx sdk.Context, account authtypes.AccountI) - - NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI - } - // ClassKeeper defines the contract needed to be fulfilled for class dependencies. ClassKeeper interface { NewID(ctx sdk.Context) string diff --git a/x/collection/keeper/keeper.go b/x/collection/keeper/keeper.go index 21479d05c5..6f7c933dbb 100644 --- a/x/collection/keeper/keeper.go +++ b/x/collection/keeper/keeper.go @@ -2,15 +2,13 @@ package keeper import ( "github.com/line/lbm-sdk/codec" - "github.com/line/lbm-sdk/telemetry" sdk "github.com/line/lbm-sdk/types" "github.com/line/lbm-sdk/x/collection" ) // Keeper defines the collection module Keeper type Keeper struct { - accountKeeper collection.AccountKeeper - classKeeper collection.ClassKeeper + classKeeper collection.ClassKeeper // The (unexposed) keys used to access the stores from the Context. storeKey sdk.StoreKey @@ -23,20 +21,11 @@ type Keeper struct { func NewKeeper( cdc codec.Codec, key sdk.StoreKey, - ak collection.AccountKeeper, ck collection.ClassKeeper, ) Keeper { return Keeper{ - accountKeeper: ak, - classKeeper: ck, - storeKey: key, - cdc: cdc, - } -} - -func (k Keeper) createAccountOnAbsence(ctx sdk.Context, address sdk.AccAddress) { - if !k.accountKeeper.HasAccount(ctx, address) { - defer telemetry.IncrCounter(1, "new", "account") - k.accountKeeper.SetAccount(ctx, k.accountKeeper.NewAccountWithAddress(ctx, address)) + classKeeper: ck, + storeKey: key, + cdc: cdc, } } diff --git a/x/collection/keeper/send.go b/x/collection/keeper/send.go index 0fa29d6288..b212279a59 100644 --- a/x/collection/keeper/send.go +++ b/x/collection/keeper/send.go @@ -47,9 +47,6 @@ func (k Keeper) addCoins(ctx sdk.Context, contractID string, address sdk.AccAddr } } - // create account if recipient does not exist. - k.createAccountOnAbsence(ctx, address) - return nil } @@ -106,9 +103,6 @@ func (k Keeper) AuthorizeOperator(ctx sdk.Context, contractID string, holder, op k.setAuthorization(ctx, contractID, holder, operator) - // create account if operator does not exist. - k.createAccountOnAbsence(ctx, operator) - return nil } diff --git a/x/collection/keeper/supply.go b/x/collection/keeper/supply.go index 72ad4f7c05..8e523219a9 100644 --- a/x/collection/keeper/supply.go +++ b/x/collection/keeper/supply.go @@ -428,9 +428,6 @@ func (k Keeper) Grant(ctx sdk.Context, contractID string, granter, grantee sdk.A func (k Keeper) grant(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission collection.Permission) { k.setGrant(ctx, contractID, grantee, permission) - - // create account if grantee does not exist. - k.createAccountOnAbsence(ctx, grantee) } func (k Keeper) Abandon(ctx sdk.Context, contractID string, grantee sdk.AccAddress, permission collection.Permission) { diff --git a/x/collection/msgs_test.go b/x/collection/msgs_test.go index 06c74482a5..2c3ec79360 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -1150,7 +1150,7 @@ func TestMsgModify(t *testing.T) { "invalid key of change": { contractID: "deadbeef", owner: addrs[0], - changes: []collection.Change{{Field: strings.ToUpper(collection.AttributeKeyName.String()) , Value: "tt"}}, + changes: []collection.Change{{Field: strings.ToUpper(collection.AttributeKeyName.String()), Value: "tt"}}, }, "invalid value of change": { contractID: "deadbeef", From ea00f9171262f379cecfc6dd3e2b6d4527bf05f7 Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Thu, 19 Jan 2023 16:10:54 +0900 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee02798aa9..d751217451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,8 +48,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (client) [\#817](https://github.com/line/lbm-sdk/pull/817) remove support for composite (BLS) type - * (x/foundation) [#834](https://github.com/line/lbm-sdk/pull/834) Apply foundation audit +* (x/token,collection) [\#866](https://github.com/line/lbm-sdk/pull/866) Do not create account on x/token,collection ### Removed * [\#853](https://github.com/line/lbm-sdk/pull/853) remove useless stub BeginBlock, EndBlock methods from modules below