Skip to content

Commit

Permalink
chore: apply review feedback
Browse files Browse the repository at this point in the history
 - move all function of `wasmplus/keeper/keeper_extension.go` to `wasmplus/keeper/keeper.go`
 - remove no need files (keeper_extension.go, metrics.go)
  • Loading branch information
zemyblue committed Feb 6, 2023
1 parent f9954a8 commit 0e91bf7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 216 deletions.
65 changes: 62 additions & 3 deletions x/wasmplus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/line/lbm-sdk/codec"
sdk "github.com/line/lbm-sdk/types"
sdkerrors "github.com/line/lbm-sdk/types/errors"
bankpluskeeper "github.com/line/lbm-sdk/x/bankplus/keeper"
paramtypes "github.com/line/lbm-sdk/x/params/types"
"github.com/line/ostracon/libs/log"
Expand All @@ -18,7 +19,7 @@ type Keeper struct {
wasmkeeper.Keeper
cdc codec.Codec
storeKey sdk.StoreKey
metrics *Metrics
metrics *wasmkeeper.Metrics
bank bankpluskeeper.Keeper
}

Expand Down Expand Up @@ -48,9 +49,8 @@ func NewKeeper(
result := Keeper{
cdc: cdc,
storeKey: storeKey,
metrics: NopMetrics(),
metrics: wasmkeeper.NopMetrics(),
bank: bankPlusKeeper,
//paramSpace: paramSpace,
}
result.Keeper = wasmkeeper.NewKeeper(
cdc,
Expand Down Expand Up @@ -89,3 +89,62 @@ func (Keeper) Logger(ctx sdk.Context) log.Logger {
func ModuleLogger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

func (k Keeper) IsInactiveContract(ctx sdk.Context, contractAddress sdk.AccAddress) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.GetInactiveContractKey(contractAddress))
}

func (k Keeper) IterateInactiveContracts(ctx sdk.Context, fn func(contractAddress sdk.AccAddress) (stop bool)) {
store := ctx.KVStore(k.storeKey)
prefix := types.InactiveContractPrefix
iterator := sdk.KVStorePrefixIterator(store, prefix)
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
contractAddress := sdk.AccAddress(iterator.Value())
if stop := fn(contractAddress); stop {
break
}
}
}

func (k Keeper) addInactiveContract(ctx sdk.Context, contractAddress sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
key := types.GetInactiveContractKey(contractAddress)

store.Set(key, contractAddress)
}

func (k Keeper) deleteInactiveContract(ctx sdk.Context, contractAddress sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
key := types.GetInactiveContractKey(contractAddress)
store.Delete(key)
}

// activateContract delete the contract address from inactivateContract list if the contract is deactivated.
func (k Keeper) activateContract(ctx sdk.Context, contractAddress sdk.AccAddress) error {
if !k.IsInactiveContract(ctx, contractAddress) {
return sdkerrors.Wrapf(wasmtypes.ErrNotFound, "no inactivate contract %s", contractAddress.String())
}

k.deleteInactiveContract(ctx, contractAddress)
k.bank.DeleteFromInactiveAddr(ctx, contractAddress)

return nil
}

// deactivateContract add the contract address to inactivateContract list.
func (k Keeper) deactivateContract(ctx sdk.Context, contractAddress sdk.AccAddress) error {
if k.IsInactiveContract(ctx, contractAddress) {
return sdkerrors.Wrapf(wasmtypes.ErrAccountExists, "already inactivate contract %s", contractAddress.String())
}
if !k.HasContractInfo(ctx, contractAddress) {
return sdkerrors.Wrapf(wasmtypes.ErrInvalid, "no contract %s", contractAddress.String())
}

k.addInactiveContract(ctx, contractAddress)
k.bank.AddToInactiveAddr(ctx, contractAddress)

return nil
}
68 changes: 0 additions & 68 deletions x/wasmplus/keeper/keeper_extension.go

This file was deleted.

145 changes: 0 additions & 145 deletions x/wasmplus/keeper/metrics.go

This file was deleted.

0 comments on commit 0e91bf7

Please sign in to comment.