Skip to content

Commit

Permalink
app, simapp - implement PR5299 - cosmos/cosmos-sdk#5299
Browse files Browse the repository at this point in the history
  • Loading branch information
Codegnosis committed Jan 27, 2020
1 parent 15bdf4d commit 7edb178
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
20 changes: 19 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
Expand Down Expand Up @@ -56,6 +57,7 @@ var (
enterprise.AppModule{},
wrkchain.AppModule{},
beacon.AppModule{},
evidence.AppModuleBasic{},
)
// account permissions
maccPerms = map[string][]string{
Expand All @@ -74,6 +76,7 @@ func MakeCodec() *codec.Codec {
ModuleBasics.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
return cdc
}

Expand Down Expand Up @@ -103,6 +106,7 @@ type mainchainApp struct {
wrkChainKeeper wrkchain.Keeper
enterpriseKeeper enterprise.Keeper
beaconKeeper beacon.Keeper
evidenceKeeper evidence.Keeper

// Module Manager
mm *module.Manager
Expand All @@ -124,7 +128,7 @@ func NewMainchainApp(

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)
wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey, evidence.StoreKey,)

tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

Expand All @@ -151,6 +155,7 @@ func NewMainchainApp(
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)
app.subspaces[evidence.ModuleName] = app.paramsKeeper.Subspace(evidence.DefaultParamspace)

// The AccountKeeper handles address -> account lookups
app.accountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -214,6 +219,17 @@ func NewMainchainApp(
auth.FeeCollectorName,
)

// create evidence keeper with evidence router
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &stakingKeeper, app.slashingKeeper,
)
evidenceRouter := evidence.NewRouter()

// TODO: register evidence routes
evidenceKeeper.SetRouter(evidenceRouter)

app.evidenceKeeper = *evidenceKeeper

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.stakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -258,6 +274,7 @@ func NewMainchainApp(
enterprise.NewAppModule(app.enterpriseKeeper),
wrkchain.NewAppModule(app.wrkChainKeeper),
beacon.NewAppModule(app.beaconKeeper),
evidence.NewAppModule(app.evidenceKeeper),
)

app.mm.SetOrderBeginBlockers(enterprise.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName)
Expand All @@ -279,6 +296,7 @@ func NewMainchainApp(
supply.ModuleName,
crisis.ModuleName,
genutil.ModuleName,
evidence.ModuleName,
)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down
21 changes: 19 additions & 2 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
Expand Down Expand Up @@ -57,6 +58,7 @@ var (
enterprise.AppModule{},
wrkchain.AppModule{},
beacon.AppModule{},
evidence.AppModuleBasic{},
)

// module account permissions
Expand All @@ -77,6 +79,7 @@ func MakeCodec() *codec.Codec {
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
return cdc
}

Expand Down Expand Up @@ -109,6 +112,7 @@ type UndSimApp struct {
WrkChainKeeper wrkchain.Keeper
EnterpriseKeeper enterprise.Keeper
BeaconKeeper beacon.Keeper
EvidenceKeeper evidence.Keeper

// the module manager
mm *module.Manager
Expand All @@ -131,7 +135,7 @@ 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)
params.StoreKey, wrkchain.StoreKey, enterprise.StoreKey, beacon.StoreKey, evidence.StoreKey,)
tKeys := sdk.NewTransientStoreKeys(params.TStoreKey)

app := &UndSimApp{
Expand All @@ -155,6 +159,7 @@ func NewUndSimApp(
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)
app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace)

// add keepers
app.AccountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -215,6 +220,17 @@ func NewUndSimApp(
auth.FeeCollectorName,
)

// create evidence keeper with evidence router
evidenceKeeper := evidence.NewKeeper(
app.cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &stakingKeeper, app.SlashingKeeper,
)
evidenceRouter := evidence.NewRouter()

// TODO: register evidence routes
evidenceKeeper.SetRouter(evidenceRouter)

app.EvidenceKeeper = *evidenceKeeper

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -259,6 +275,7 @@ func NewUndSimApp(
enterprise.NewAppModule(app.EnterpriseKeeper),
wrkchain.NewAppModule(app.WrkChainKeeper),
beacon.NewAppModule(app.BeaconKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -274,7 +291,7 @@ func NewUndSimApp(
auth.ModuleName, distr.ModuleName, staking.ModuleName,
bank.ModuleName, slashing.ModuleName, wrkchain.ModuleName, beacon.ModuleName,
enterprise.ModuleName, mint.ModuleName, supply.ModuleName,
crisis.ModuleName, genutil.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down

0 comments on commit 7edb178

Please sign in to comment.