Skip to content

Commit

Permalink
app, simapp - use subspaces map
Browse files Browse the repository at this point in the history
  • Loading branch information
Codegnosis committed Jan 27, 2020
1 parent b07cf7a commit 15bdf4d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 58 deletions.
57 changes: 29 additions & 28 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,44 +126,44 @@ 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{
BaseApp: bApp,
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(),
)

Expand All @@ -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,
Expand All @@ -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(),
)
Expand All @@ -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,
Expand All @@ -223,7 +224,7 @@ func NewMainchainApp(

app.wrkChainKeeper = wrkchain.NewKeeper(
keys[wrkchain.StoreKey],
wrkchainSubspace,
app.subspaces[wrkchain.ModuleName],
wrkchain.DefaultCodespace,
app.cdc,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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])
Expand Down
110 changes: 80 additions & 30 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -173,7 +223,7 @@ func NewUndSimApp(

app.WrkChainKeeper = wrkchain.NewKeeper(
keys[wrkchain.StoreKey],
wrkchainSubspace,
app.subspaces[wrkchain.ModuleName],
wrkchain.DefaultCodespace,
app.cdc,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -251,7 +301,7 @@ func NewUndSimApp(

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountTransientStores(tKeys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 15bdf4d

Please sign in to comment.