Skip to content

Commit

Permalink
refactor: v0.50 store app wiring (#3672)
Browse files Browse the repository at this point in the history
* refactor: v0.50 store app wiring

* updates

* updates

---------

Co-authored-by: Danilo Pantani <[email protected]>
  • Loading branch information
julienrbrt and Pantani authored Sep 29, 2023
1 parent c2b960e commit 7fd3d54
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosanalysis/cosmosanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const (
)

var AppImplementation = []string{
"Name",
"GetKey",
"AppCodec",
"TxConfig",
"RegisterAPIRoutes",
}
Expand Down
28 changes: 11 additions & 17 deletions ignite/templates/app/files/app/app.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ type App struct {
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry

// non depinject support modules store keys
keys map[string]*storetypes.KVStoreKey
memKeys map[string]*storetypes.MemoryStoreKey
tkeys map[string]*storetypes.TransientStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
Expand Down Expand Up @@ -233,8 +228,8 @@ func New(
&app.FeeGrantKeeper,
&app.GroupKeeper,
&app.ConsensusParamsKeeper,
// this line is used by starport scaffolding # stargate/app/keeperDefinition
&app.CircuitBreakerKeeper,
// this line is used by starport scaffolding # stargate/app/keeperDefinition
); err != nil {
panic(err)
}
Expand Down Expand Up @@ -317,9 +312,6 @@ func New(
return app
}

// Name returns the name of the App
func (app *App) Name() string { return app.BaseApp.Name() }

// LegacyAmino returns App's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
Expand Down Expand Up @@ -348,10 +340,6 @@ func (app *App) TxConfig() client.TxConfig {

// GetKey returns the KVStoreKey for the provided store key.
func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey {
if key, ok := app.keys[storeKey]; ok {
return key
}

sk := app.UnsafeFindStoreKey(storeKey)
kvStoreKey, ok := sk.(*storetypes.KVStoreKey)
if !ok {
Expand All @@ -360,6 +348,16 @@ func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey {
return kvStoreKey
}

// GetMemKey returns the MemoryStoreKey for the provided store key.
func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
key, ok := app.UnsafeFindStoreKey(storeKey).(*storetypes.MemoryStoreKey)
if !ok {
return nil
}

return key
}

// kvStoreKeys returns all the kv store keys registered inside App.
func (app *App) kvStoreKeys() map[string]*storetypes.KVStoreKey {
keys := make(map[string]*storetypes.KVStoreKey)
Expand All @@ -369,10 +367,6 @@ func (app *App) kvStoreKeys() map[string]*storetypes.KVStoreKey {
}
}

for _, kv := range app.keys {
keys[kv.Name()] = kv
}

return keys
}

Expand Down
29 changes: 14 additions & 15 deletions ignite/templates/app/files/app/ibc.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ import (

func (app *App) registerIBCModules() {
// set up non depinject support modules store keys
app.keys = storetypes.NewKVStoreKeys(
capabilitytypes.StoreKey,
ibcexported.StoreKey,
ibctransfertypes.StoreKey,
ibcfeetypes.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
)
app.MountKVStores(app.keys)
app.tkeys = storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
app.MountTransientStores(app.tkeys)
app.memKeys = storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
app.MountMemoryStores(app.memKeys)
if err := app.RegisterStores(
storetypes.NewKVStoreKey(capabilitytypes.StoreKey),
storetypes.NewKVStoreKey(ibcexported.StoreKey),
storetypes.NewKVStoreKey(ibctransfertypes.StoreKey),
storetypes.NewKVStoreKey(ibcfeetypes.StoreKey),
storetypes.NewKVStoreKey(icahosttypes.StoreKey),
storetypes.NewKVStoreKey(icacontrollertypes.StoreKey),
storetypes.NewMemoryStoreKey(capabilitytypes.MemStoreKey),
storetypes.NewTransientStoreKey(paramstypes.TStoreKey),
); err != nil {
panic(err)
}

// set params subspaces
for _, m := range []string{ibctransfertypes.ModuleName, ibcexported.ModuleName, icahosttypes.SubModuleName, icacontrollertypes.SubModuleName} {
Expand All @@ -53,8 +52,8 @@ func (app *App) registerIBCModules() {
// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
app.AppCodec(),
app.keys[capabilitytypes.StoreKey],
app.memKeys[capabilitytypes.MemStoreKey],
app.GetKey(capabilitytypes.StoreKey),
app.GetMemKey(capabilitytypes.MemStoreKey),
)

// add capability keeper and ScopeToModule for ibc module
Expand Down

0 comments on commit 7fd3d54

Please sign in to comment.