From 15bdf4d176d8e547be70b44424e27ea81b7c81f9 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Mon, 27 Jan 2020 09:39:45 +0000 Subject: [PATCH] app, simapp - use subspaces map --- app/app.go | 57 +++++++++++++------------- simapp/app.go | 110 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 109 insertions(+), 58 deletions(-) diff --git a/app/app.go b/app/app.go index 9dedfe19..110b55a3 100644 --- a/app/app.go +++ b/app/app.go @@ -85,7 +85,10 @@ type mainchainApp struct { // keys to access the substores keys map[string]*sdk.KVStoreKey - tkeys map[string]*sdk.TransientStoreKey + tKeys map[string]*sdk.TransientStoreKey + + // subspaces + subspaces map[string]params.Subspace // Keepers accountKeeper auth.AccountKeeper @@ -123,7 +126,7 @@ func NewMainchainApp( supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, params.StoreKey, wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey) - tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey) + tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey) // Here you initialize your application with the store keys it requires var app = &mainchainApp{ @@ -131,36 +134,36 @@ func NewMainchainApp( cdc: cdc, invCheckPeriod: invCheckPeriod, keys: keys, - tkeys: tkeys, + tKeys: tKeys, + subspaces: make(map[string]params.Subspace), } // The ParamsKeeper handles parameter storage for the application - app.paramsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey], params.DefaultCodespace) + app.paramsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tKeys[params.TStoreKey]) // Set specific subspaces - authSubspace := app.paramsKeeper.Subspace(auth.DefaultParamspace) - bankSupspace := app.paramsKeeper.Subspace(bank.DefaultParamspace) - stakingSubspace := app.paramsKeeper.Subspace(staking.DefaultParamspace) - mintSubspace := app.paramsKeeper.Subspace(mint.DefaultParamspace) - distrSubspace := app.paramsKeeper.Subspace(distr.DefaultParamspace) - slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace) - crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace) - enterpriseSubspace := app.paramsKeeper.Subspace(enterprise.DefaultParamspace) - wrkchainSubspace := app.paramsKeeper.Subspace(wrkchain.DefaultParamspace) - beaconSubspace := app.paramsKeeper.Subspace(beacon.DefaultParamspace) + app.subspaces[auth.ModuleName] = app.paramsKeeper.Subspace(auth.DefaultParamspace) + app.subspaces[bank.ModuleName] = app.paramsKeeper.Subspace(bank.DefaultParamspace) + app.subspaces[staking.ModuleName] = app.paramsKeeper.Subspace(staking.DefaultParamspace) + app.subspaces[mint.ModuleName] = app.paramsKeeper.Subspace(mint.DefaultParamspace) + app.subspaces[distr.ModuleName] = app.paramsKeeper.Subspace(distr.DefaultParamspace) + app.subspaces[slashing.ModuleName] = app.paramsKeeper.Subspace(slashing.DefaultParamspace) + app.subspaces[crisis.ModuleName] = app.paramsKeeper.Subspace(crisis.DefaultParamspace) + app.subspaces[enterprise.ModuleName] = app.paramsKeeper.Subspace(enterprise.DefaultParamspace) + app.subspaces[wrkchain.ModuleName] = app.paramsKeeper.Subspace(wrkchain.DefaultParamspace) + app.subspaces[beacon.ModuleName] = app.paramsKeeper.Subspace(beacon.DefaultParamspace) // The AccountKeeper handles address -> account lookups app.accountKeeper = auth.NewAccountKeeper( app.cdc, keys[auth.StoreKey], - authSubspace, + app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, ) // The BankKeeper allows you perform sdk.Coins interactions app.bankKeeper = bank.NewBaseKeeper( app.accountKeeper, - bankSupspace, - bank.DefaultCodespace, + app.subspaces[bank.ModuleName], app.ModuleAccountAddrs(), ) @@ -175,13 +178,13 @@ func NewMainchainApp( // The staking keeper stakingKeeper := staking.NewKeeper( - app.cdc, keys[staking.StoreKey], app.supplyKeeper, stakingSubspace, staking.DefaultCodespace, + app.cdc, keys[staking.StoreKey], app.supplyKeeper, app.subspaces[staking.ModuleName], ) app.mintKeeper = mint.NewKeeper( app.cdc, keys[mint.StoreKey], - mintSubspace, + app.subspaces[mint.ModuleName], &stakingKeeper, app.supplyKeeper, auth.FeeCollectorName, @@ -190,10 +193,9 @@ func NewMainchainApp( app.distrKeeper = distr.NewKeeper( app.cdc, keys[distr.StoreKey], - distrSubspace, + app.subspaces[distr.ModuleName], &stakingKeeper, app.supplyKeeper, - distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs(), ) @@ -202,12 +204,11 @@ func NewMainchainApp( app.cdc, keys[slashing.StoreKey], &stakingKeeper, - slashingSubspace, - slashing.DefaultCodespace, + app.subspaces[slashing.ModuleName], ) app.crisisKeeper = crisis.NewKeeper( - crisisSubspace, + app.subspaces[crisis.ModuleName], invCheckPeriod, app.supplyKeeper, auth.FeeCollectorName, @@ -223,7 +224,7 @@ func NewMainchainApp( app.wrkChainKeeper = wrkchain.NewKeeper( keys[wrkchain.StoreKey], - wrkchainSubspace, + app.subspaces[wrkchain.ModuleName], wrkchain.DefaultCodespace, app.cdc, ) @@ -232,14 +233,14 @@ func NewMainchainApp( keys[enterprise.StoreKey], app.supplyKeeper, app.accountKeeper, - enterpriseSubspace, + app.subspaces[enterprise.ModuleName], enterprise.DefaultCodespace, app.cdc, ) app.beaconKeeper = beacon.NewKeeper( keys[beacon.StoreKey], - beaconSubspace, + app.subspaces[beacon.ModuleName], beacon.DefaultCodespace, app.cdc, ) @@ -304,7 +305,7 @@ func NewMainchainApp( // initialize stores app.MountKVStores(keys) - app.MountTransientStores(tkeys) + app.MountTransientStores(tKeys) if loadLatest { err := app.LoadLatestVersion(app.keys[bam.MainStoreKey]) diff --git a/simapp/app.go b/simapp/app.go index 424288a0..e6ccee4a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -91,7 +91,10 @@ type UndSimApp struct { // keys to access the substores keys map[string]*sdk.KVStoreKey - tkeys map[string]*sdk.TransientStoreKey + tKeys map[string]*sdk.TransientStoreKey + + // subspaces + subspaces map[string]params.Subspace // keepers AccountKeeper auth.AccountKeeper @@ -129,41 +132,88 @@ func NewUndSimApp( keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey, params.StoreKey, wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey) - tkeys := sdk.NewTransientStoreKeys(params.TStoreKey) + tKeys := sdk.NewTransientStoreKeys(params.TStoreKey) app := &UndSimApp{ BaseApp: bApp, cdc: cdc, invCheckPeriod: invCheckPeriod, keys: keys, - tkeys: tkeys, + tKeys: tKeys, + subspaces: make(map[string]params.Subspace), } // init params keeper and subspaces - app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey], params.DefaultCodespace) - authSubspace := app.ParamsKeeper.Subspace(auth.DefaultParamspace) - bankSubspace := app.ParamsKeeper.Subspace(bank.DefaultParamspace) - stakingSubspace := app.ParamsKeeper.Subspace(staking.DefaultParamspace) - mintSubspace := app.ParamsKeeper.Subspace(mint.DefaultParamspace) - distrSubspace := app.ParamsKeeper.Subspace(distr.DefaultParamspace) - slashingSubspace := app.ParamsKeeper.Subspace(slashing.DefaultParamspace) - crisisSubspace := app.ParamsKeeper.Subspace(crisis.DefaultParamspace) - enterpriseSubspace := app.ParamsKeeper.Subspace(enterprise.DefaultParamspace) - wrkchainSubspace := app.ParamsKeeper.Subspace(wrkchain.DefaultParamspace) - beaconSubspace := app.ParamsKeeper.Subspace(beacon.DefaultParamspace) + app.ParamsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tKeys[params.TStoreKey]) + app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) + app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace) + app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace) + app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace) + app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace) + app.subspaces[slashing.ModuleName] = app.ParamsKeeper.Subspace(slashing.DefaultParamspace) + app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace) + app.subspaces[enterprise.ModuleName] = app.ParamsKeeper.Subspace(enterprise.DefaultParamspace) + app.subspaces[wrkchain.ModuleName] = app.ParamsKeeper.Subspace(wrkchain.DefaultParamspace) + app.subspaces[beacon.ModuleName] = app.ParamsKeeper.Subspace(beacon.DefaultParamspace) // add keepers - app.AccountKeeper = auth.NewAccountKeeper(app.cdc, keys[auth.StoreKey], authSubspace, auth.ProtoBaseAccount) - app.BankKeeper = bank.NewBaseKeeper(app.AccountKeeper, bankSubspace, bank.DefaultCodespace, app.ModuleAccountAddrs()) - app.SupplyKeeper = supply.NewKeeper(app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms) - stakingKeeper := staking.NewKeeper(app.cdc, keys[staking.StoreKey], - app.SupplyKeeper, stakingSubspace, staking.DefaultCodespace) - app.MintKeeper = mint.NewKeeper(app.cdc, keys[mint.StoreKey], mintSubspace, &stakingKeeper, app.SupplyKeeper, auth.FeeCollectorName) - app.DistrKeeper = distr.NewKeeper(app.cdc, keys[distr.StoreKey], distrSubspace, &stakingKeeper, - app.SupplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs()) - app.SlashingKeeper = slashing.NewKeeper(app.cdc, keys[slashing.StoreKey], &stakingKeeper, - slashingSubspace, slashing.DefaultCodespace) - app.CrisisKeeper = crisis.NewKeeper(crisisSubspace, invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName) + app.AccountKeeper = auth.NewAccountKeeper( + app.cdc, + keys[auth.StoreKey], + app.subspaces[auth.ModuleName], + auth.ProtoBaseAccount, + ) + + app.BankKeeper = bank.NewBaseKeeper( + app.AccountKeeper, + app.subspaces[bank.ModuleName], + app.ModuleAccountAddrs(), + ) + + app.SupplyKeeper = supply.NewKeeper( + app.cdc, + keys[supply.StoreKey], + app.AccountKeeper, + app.BankKeeper, + maccPerms, + ) + + stakingKeeper := staking.NewKeeper( + app.cdc, keys[staking.StoreKey], app.SupplyKeeper, app.subspaces[staking.ModuleName], + ) + + app.MintKeeper = mint.NewKeeper( + app.cdc, + keys[mint.StoreKey], + app.subspaces[mint.ModuleName], + &stakingKeeper, + app.SupplyKeeper, + auth.FeeCollectorName, + ) + + app.DistrKeeper = distr.NewKeeper( + app.cdc, + keys[distr.StoreKey], + app.subspaces[distr.ModuleName], + &stakingKeeper, + app.SupplyKeeper, + auth.FeeCollectorName, + app.ModuleAccountAddrs(), + ) + + app.SlashingKeeper = slashing.NewKeeper( + app.cdc, + keys[slashing.StoreKey], + &stakingKeeper, + app.subspaces[slashing.ModuleName], + ) + + app.CrisisKeeper = crisis.NewKeeper( + app.subspaces[crisis.ModuleName], + invCheckPeriod, + app.SupplyKeeper, + auth.FeeCollectorName, + ) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks @@ -173,7 +223,7 @@ func NewUndSimApp( app.WrkChainKeeper = wrkchain.NewKeeper( keys[wrkchain.StoreKey], - wrkchainSubspace, + app.subspaces[wrkchain.ModuleName], wrkchain.DefaultCodespace, app.cdc, ) @@ -182,14 +232,14 @@ func NewUndSimApp( keys[enterprise.StoreKey], app.SupplyKeeper, app.AccountKeeper, - enterpriseSubspace, + app.subspaces[enterprise.ModuleName], enterprise.DefaultCodespace, app.cdc, ) app.BeaconKeeper = beacon.NewKeeper( keys[beacon.StoreKey], - beaconSubspace, + app.subspaces[beacon.ModuleName], beacon.DefaultCodespace, app.cdc, ) @@ -251,7 +301,7 @@ func NewUndSimApp( // initialize stores app.MountKVStores(keys) - app.MountTransientStores(tkeys) + app.MountTransientStores(tKeys) // initialize BaseApp app.SetInitChainer(app.InitChainer) @@ -321,7 +371,7 @@ func (app *UndSimApp) GetKey(storeKey string) *sdk.KVStoreKey { // GetTKey returns the TransientStoreKey for the provided store key func (app *UndSimApp) GetTKey(storeKey string) *sdk.TransientStoreKey { - return app.tkeys[storeKey] + return app.tKeys[storeKey] } // GetMaccPerms returns a copy of the module account permissions