2019-05-16 08:25:32 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2019-05-16 08:25:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
|
2019-07-19 06:43:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
|
2019-08-13 15:16:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/simulation"
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-08-13 15:16:03 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
_ module.AppModuleSimulation = AppModuleSimulation{}
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// AppModuleBasic defines the basic application module used by the slashing module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the slashing module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
2019-06-05 16:26:17 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterCodec registers the slashing module's types for the given codec.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
|
|
|
RegisterCodec(cdc)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the slashing
|
|
|
|
// module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
2019-06-05 16:26:17 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// ValidateGenesis performs genesis state validation for the slashing module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
|
|
|
var data GenesisState
|
2019-06-05 16:26:17 -07:00
|
|
|
err := ModuleCdc.UnmarshalJSON(bz, &data)
|
2019-05-16 08:25:32 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ValidateGenesis(data)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterRESTRoutes registers the REST routes for the slashing module.
|
2019-06-06 08:43:15 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
|
|
|
|
rest.RegisterRoutes(ctx, rtr)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetTxCmd returns the root tx command for the slashing module.
|
2019-06-05 16:26:17 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
return cli.GetTxCmd(cdc)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetQueryCmd returns no root query command for the slashing module.
|
2019-06-05 16:26:17 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
return cli.GetQueryCmd(StoreKey, cdc)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModuleSimulation defines the module simulation functions used by the slashing module.
|
|
|
|
type AppModuleSimulation struct{}
|
|
|
|
|
|
|
|
// RegisterStoreDecoder registers a decoder for slashing module's types
|
|
|
|
func (AppModuleSimulation) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
|
|
|
sdr[StoreKey] = simulation.DecodeStore
|
|
|
|
}
|
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModule implements an application module for the slashing module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-08-13 15:16:03 -07:00
|
|
|
AppModuleSimulation
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
keeper Keeper
|
2019-06-10 02:57:38 -07:00
|
|
|
stakingKeeper types.StakingKeeper
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2019-06-10 02:57:38 -07:00
|
|
|
func NewAppModule(keeper Keeper, stakingKeeper types.StakingKeeper) AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
return AppModule{
|
2019-08-13 15:16:03 -07:00
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
AppModuleSimulation: AppModuleSimulation{},
|
|
|
|
keeper: keeper,
|
|
|
|
stakingKeeper: stakingKeeper,
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the slashing module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Name() string {
|
|
|
|
return ModuleName
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterInvariants registers the slashing module invariants.
|
2019-06-06 13:32:38 -07:00
|
|
|
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Route returns the message routing key for the slashing module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Route() string {
|
|
|
|
return RouterKey
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// NewHandler returns an sdk.Handler for the slashing module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) NewHandler() sdk.Handler {
|
|
|
|
return NewHandler(am.keeper)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// QuerierRoute returns the slashing module's querier route name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) QuerierRoute() string {
|
|
|
|
return QuerierRoute
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// NewQuerierHandler returns the slashing module sdk.Querier.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
|
|
|
return NewQuerier(am.keeper)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// InitGenesis performs genesis initialization for the slashing module. It returns
|
|
|
|
// no validator updates.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
|
|
|
var genesisState GenesisState
|
2019-06-05 16:26:17 -07:00
|
|
|
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
2019-05-16 08:25:32 -07:00
|
|
|
InitGenesis(ctx, am.keeper, am.stakingKeeper, genesisState)
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the slashing
|
|
|
|
// module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
|
|
|
gs := ExportGenesis(ctx, am.keeper)
|
2019-06-05 16:26:17 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(gs)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// BeginBlock returns the begin blocker for the slashing module.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
|
|
|
BeginBlocker(ctx, req, am.keeper)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// EndBlock returns the end blocker for the slashing module. It returns no validator
|
|
|
|
// updates.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|