Skip to content

Commit

Permalink
Move appKeepers struct to a different package (#1327)
Browse files Browse the repository at this point in the history
* create module keepers && function InitNormalKeepers

* move method InitSpecialKeepers and initParamsKeeper to AppKeepers

* change in app.go && remove old keepers

* fix bug by forget transfer module

* add TxFeesKeeper to Hook

* move keys generate and transfer module to appkeepers module && functions for these

* move key's function to keys.go

* add AppKeepers empty struct initialization
  • Loading branch information
vuong177 authored Apr 25, 2022
1 parent ed10116 commit 66ebf33
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 260 deletions.
63 changes: 30 additions & 33 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/CosmWasm/wasmd/x/wasm"
transfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -37,11 +36,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v7/app/keepers"
appparams "github.com/osmosis-labs/osmosis/v7/app/params"
v4 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v4"
v5 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v5"
Expand Down Expand Up @@ -113,22 +112,16 @@ func GetWasmEnabledProposals() []wasm.ProposalType {
// capabilities aren't needed for testing.
type OsmosisApp struct {
*baseapp.BaseApp
appKeepers
keepers.AppKeepers

cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
invCheckPeriod uint

// keys to access the substores
keys map[string]*sdk.KVStoreKey
tkeys map[string]*sdk.TransientStoreKey
memKeys map[string]*sdk.MemoryStoreKey

transferModule transfer.AppModule
mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator
mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator
}

func init() {
Expand Down Expand Up @@ -164,37 +157,41 @@ func NewOsmosisApp(
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)

// Define what keys will be used in the cosmos-sdk key/value store.
// Cosmos-SDK modules each have a "key" that allows the application to reference what they've stored on the chain.
// Keys are in keys.go to kep app.go as brief as possible.
keys := sdk.NewKVStoreKeys(KVStoreKeys()...)

// Define transient store keys
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)

// MemKeys are for information that is stored only in RAM.
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

app := &OsmosisApp{
AppKeepers: keepers.AppKeepers{},
BaseApp: bApp,
cdc: cdc,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
}

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}

app.InitSpecialKeepers(skipUpgradeHeights, homePath, invCheckPeriod)
app.InitSpecialKeepers(
appCodec,
bApp,
wasmDir,
cdc,
invCheckPeriod,
skipUpgradeHeights,
homePath,
)
app.setupUpgradeStoreLoaders()
app.InitNormalKeepers(wasmDir, wasmConfig, wasmEnabledProposals, wasmOpts)
app.InitNormalKeepers(
appCodec,
bApp,
maccPerms,
wasmDir,
wasmConfig,
wasmEnabledProposals,
wasmOpts,
app.BlockedAddrs(),
)

app.SetupHooks()

/**** Module Options ****/
Expand Down Expand Up @@ -252,9 +249,9 @@ func NewOsmosisApp(
testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)
app.MountKVStores(app.GetKVStoreKey())
app.MountTransientStores(app.GetTransientStoreKey())
app.MountMemoryStores(app.GetMemoryStoreKey())

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
Expand All @@ -263,7 +260,7 @@ func NewOsmosisApp(
NewAnteHandler(
appOpts,
wasmConfig,
keys[wasm.StoreKey],
app.GetKey(wasm.StoreKey),
app.AccountKeeper,
app.BankKeeper,
app.TxFeesKeeper,
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (app *OsmosisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

Expand Down
Loading

0 comments on commit 66ebf33

Please sign in to comment.