2019-05-16 08:25:32 -07:00
|
|
|
package crisis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-01-09 12:14:23 -08:00
|
|
|
"fmt"
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2020-06-06 00:59:57 -07:00
|
|
|
"github.com/gogo/protobuf/grpc"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2020-06-01 05:46:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-05-16 08:25:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-07-08 01:23:34 -07:00
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
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/crisis/client/cli"
|
2020-03-03 08:45:02 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/crisis/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-08-28 07:58:25 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// AppModuleBasic defines the basic application module used by the crisis module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// Name returns the crisis module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
2020-06-14 06:59:25 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// RegisterCodec registers the crisis module's types for the given codec.
|
2020-08-10 12:41:21 -07:00
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
|
2020-06-14 06:59:25 -07:00
|
|
|
types.RegisterCodec(cdc)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the crisis
|
|
|
|
// module.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
|
2020-06-14 06:59:25 -07:00
|
|
|
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// ValidateGenesis performs genesis state validation for the crisis module.
|
2020-07-25 01:10:04 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error {
|
2019-06-28 13:11:27 -07:00
|
|
|
var data types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
2020-06-14 06:59:25 -07:00
|
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
2019-06-28 13:11:27 -07:00
|
|
|
}
|
2020-01-09 12:14:23 -08:00
|
|
|
|
2020-08-11 07:22:30 -07:00
|
|
|
return types.ValidateGenesis(&data)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// RegisterRESTRoutes registers no REST routes for the crisis module.
|
2020-06-01 05:46:03 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// GetTxCmd returns the root tx command for the crisis module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (b AppModuleBasic) GetTxCmd() *cobra.Command {
|
2020-07-08 01:23:34 -07:00
|
|
|
return cli.NewTxCmd()
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// GetQueryCmd returns no root query command for the crisis module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2020-07-23 19:45:34 -07:00
|
|
|
// RegisterInterfaces registers interfaces and implementations of the crisis
|
2020-07-08 01:23:34 -07:00
|
|
|
// module.
|
2020-07-23 19:45:34 -07:00
|
|
|
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
2020-07-08 01:23:34 -07:00
|
|
|
types.RegisterInterfaces(registry)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
//____________________________________________________________________________
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// AppModule implements an application module for the crisis module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-08-06 12:11:55 -07:00
|
|
|
|
|
|
|
// NOTE: We store a reference to the keeper here so that after a module
|
|
|
|
// manager is created, the invariants can be properly registered and
|
|
|
|
// executed.
|
|
|
|
keeper *keeper.Keeper
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2019-08-06 12:11:55 -07:00
|
|
|
func NewAppModule(keeper *keeper.Keeper) AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
return AppModule{
|
2019-08-28 07:58:25 -07:00
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// Name returns the crisis module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Name() string {
|
2020-06-14 06:59:25 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// RegisterInvariants performs a no-op.
|
2019-06-06 13:32:38 -07:00
|
|
|
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// Route returns the message routing key for the crisis module.
|
2020-06-11 08:37:23 -07:00
|
|
|
func (am AppModule) Route() sdk.Route {
|
2020-06-10 11:48:16 -07:00
|
|
|
return sdk.NewRoute(RouterKey, NewHandler(*am.keeper))
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// QuerierRoute returns no querier route.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) QuerierRoute() string { return "" }
|
|
|
|
|
2020-07-24 12:04:29 -07:00
|
|
|
// LegacyQuerierHandler returns no sdk.Querier.
|
|
|
|
func (AppModule) LegacyQuerierHandler(codec.JSONMarshaler) sdk.Querier { return nil }
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2020-07-20 06:09:57 -07:00
|
|
|
// RegisterQueryService registers a GRPC query service to respond to the
|
|
|
|
// module-specific GRPC queries.
|
2020-06-06 00:59:57 -07:00
|
|
|
func (am AppModule) RegisterQueryService(grpc.Server) {}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// InitGenesis performs genesis initialization for the crisis module. It returns
|
|
|
|
// no validator updates.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
2020-06-14 06:59:25 -07:00
|
|
|
var genesisState types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
2020-08-11 07:22:30 -07:00
|
|
|
am.keeper.InitGenesis(ctx, &genesisState)
|
2019-06-26 09:41:14 -07:00
|
|
|
am.keeper.AssertInvariants(ctx)
|
2019-05-16 08:25:32 -07:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the crisis
|
|
|
|
// module.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
|
2020-07-12 23:55:58 -07:00
|
|
|
gs := am.keeper.ExportGenesis(ctx)
|
2020-02-18 04:50:13 -08:00
|
|
|
return cdc.MustMarshalJSON(gs)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// BeginBlock performs a no-op.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-06 12:11:55 -07:00
|
|
|
// EndBlock returns the end blocker for the crisis module. It returns no validator
|
|
|
|
// updates.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
2019-08-06 12:11:55 -07:00
|
|
|
EndBlocker(ctx, *am.keeper)
|
2019-06-26 09:03:25 -07:00
|
|
|
return []abci.ValidatorUpdate{}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|