Skip to content

Commit

Permalink
fix: do not create account on x/token,collection (#866)
Browse files Browse the repository at this point in the history
* Get rid of account keeper from x/token

* Get rid of account keeper from x/collection

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Feb 3, 2023
1 parent 3933ad1 commit ef335aa
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 68 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ 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/collection,token) [#849](https://github.com/line/lbm-sdk/pull/849) Introduce codespace into x/collection,token
* (x/token,collection) [#863](https://github.com/line/lbm-sdk/pull/863) Update x/collection,token proto
* (x/foundation) [\#834](https://github.com/line/lbm-sdk/pull/834) Apply foundation audit
* (x/collection,token) [\#849](https://github.com/line/lbm-sdk/pull/849) Introduce codespace into x/collection,token
* (x/token,collection) [\#863](https://github.com/line/lbm-sdk/pull/863) Update x/collection,token proto
* (x/collection,token) [\#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
Expand All @@ -59,8 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Breaking Changes
* (rest) [\#807](https://github.com/line/lbm-sdk/pull/807) remove legacy REST API

* (codec) [#833](https://github.com/line/lbm-sdk/pull/833) Fix foundation amino codec
* (codec) [\#833](https://github.com/line/lbm-sdk/pull/833) Fix foundation amino codec

### Build, CI
* (ci) [\#829](https://github.com/line/lbm-sdk/pull/829) automate release process
Expand Down
4 changes: 2 additions & 2 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ func NewSimApp(
app.FoundationKeeper = foundationkeeper.NewKeeper(appCodec, keys[foundation.StoreKey], app.BaseApp.MsgServiceRouter(), app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, foundationConfig, foundation.DefaultAuthority().String())

app.ClassKeeper = classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.AccountKeeper, app.ClassKeeper)
app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], app.AccountKeeper, app.ClassKeeper)
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.ClassKeeper)
app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], app.ClassKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down
9 changes: 0 additions & 9 deletions x/collection/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions x/collection/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ 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"
"github.com/line/lbm-sdk/x/token/class"
)

// 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
Expand All @@ -24,21 +22,12 @@ 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,
}
}

Expand Down
6 changes: 0 additions & 6 deletions x/collection/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func (k Keeper) addCoins(ctx sdk.Context, contractID string, address sdk.AccAddr
k.setOwner(ctx, contractID, coin.TokenId, address)
}
}

// create account if recipient does not exist.
k.createAccountOnAbsence(ctx, address)
}

func (k Keeper) subtractCoins(ctx sdk.Context, contractID string, address sdk.AccAddress, amount []collection.Coin) error {
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 0 additions & 3 deletions x/collection/keeper/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,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) {
Expand Down
9 changes: 0 additions & 9 deletions x/token/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions x/token/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,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
Expand All @@ -23,14 +22,12 @@ 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,
}
}

Expand Down
8 changes: 0 additions & 8 deletions x/token/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,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
}

Expand Down Expand Up @@ -87,10 +83,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 {
Expand Down
4 changes: 0 additions & 4 deletions x/token/keeper/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,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) {
Expand Down

0 comments on commit ef335aa

Please sign in to comment.