Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not create account on x/token,collection #866

Merged
merged 5 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ 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/collection,token) [\#849](https://github.com/line/lbm-sdk/pull/849) Introduce codespace into x/collection,token
* (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 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