2019-05-16 08:25:32 -07:00
|
|
|
package gov
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// DONTCOVER
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
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/gov/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
2019-05-16 08:25:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-06-05 16:26:17 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// AppModuleBasic - app module basics object
|
2019-06-05 16:26:17 -07:00
|
|
|
type AppModuleBasic struct {
|
|
|
|
proposalHandlers []client.ProposalHandler // proposal handlers which live in governance cli and rest
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
// NewAppModuleBasic creates a new AppModuleBasic object
|
|
|
|
func NewAppModuleBasic(proposalHandlers ...client.ProposalHandler) AppModuleBasic {
|
|
|
|
return AppModuleBasic{
|
|
|
|
proposalHandlers: proposalHandlers,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// Name - module name
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// RegisterCodec -register module codec
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
|
|
|
RegisterCodec(cdc)
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// DefaultGenesis - default genesis state
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
2019-08-08 12:51:18 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(DefaultGenesisState())
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ValidateGenesis - module validate genesis
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
|
|
|
var data GenesisState
|
2019-08-08 12:51:18 -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-08 12:51:18 -07:00
|
|
|
// RegisterRESTRoutes - register rest routes
|
2019-06-06 08:43:15 -07:00
|
|
|
func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {
|
2019-06-05 16:26:17 -07:00
|
|
|
var proposalRESTHandlers []rest.ProposalRESTHandler
|
|
|
|
for _, proposalHandler := range a.proposalHandlers {
|
2019-06-06 08:43:15 -07:00
|
|
|
proposalRESTHandlers = append(proposalRESTHandlers, proposalHandler.RESTHandler(ctx))
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-06-06 08:43:15 -07:00
|
|
|
rest.RegisterRoutes(ctx, rtr, proposalRESTHandlers)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// GetTxCmd gets the root tx command of this module
|
2019-06-05 16:26:17 -07:00
|
|
|
func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
|
|
|
|
var proposalCLIHandlers []*cobra.Command
|
|
|
|
for _, proposalHandler := range a.proposalHandlers {
|
|
|
|
proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(cdc))
|
|
|
|
}
|
|
|
|
|
|
|
|
return cli.GetTxCmd(StoreKey, cdc, proposalCLIHandlers)
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// GetQueryCmd gets the root query command of this module
|
2019-06-05 16:26:17 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
return cli.GetQueryCmd(StoreKey, cdc)
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
//___________________________
|
2019-08-08 12:51:18 -07:00
|
|
|
|
|
|
|
// AppModule - app module object
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-06-28 13:11:27 -07:00
|
|
|
keeper Keeper
|
2019-08-08 12:51:18 -07:00
|
|
|
supplyKeeper types.SupplyKeeper
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2019-08-08 12:51:18 -07:00
|
|
|
func NewAppModule(keeper Keeper, supplyKeeper types.SupplyKeeper) AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
return AppModule{
|
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
2019-06-28 13:11:27 -07:00
|
|
|
supplyKeeper: supplyKeeper,
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// Name - module name
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Name() string {
|
2019-08-08 12:51:18 -07:00
|
|
|
return ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// RegisterInvariants registers module invariants
|
2019-06-28 13:11:27 -07:00
|
|
|
func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
|
|
|
|
RegisterInvariants(ir, am.keeper)
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// Route - module message route name
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Route() string {
|
|
|
|
return RouterKey
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// NewHandler - module handler
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) NewHandler() sdk.Handler {
|
|
|
|
return NewHandler(am.keeper)
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// QuerierRoute - module querier route name
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) QuerierRoute() string {
|
|
|
|
return QuerierRoute
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// NewQuerierHandler - module querier
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
|
|
|
return NewQuerier(am.keeper)
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// InitGenesis - module init-genesis
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
|
|
|
var genesisState GenesisState
|
2019-08-08 12:51:18 -07:00
|
|
|
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
2019-06-28 13:11:27 -07:00
|
|
|
InitGenesis(ctx, am.keeper, am.supplyKeeper, genesisState)
|
2019-05-16 08:25:32 -07:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// ExportGenesis - module export genesis
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
|
|
|
gs := ExportGenesis(ctx, am.keeper)
|
2019-08-08 12:51:18 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(gs)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:51:18 -07:00
|
|
|
// BeginBlock - module begin-block
|
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-08 12:51:18 -07:00
|
|
|
// EndBlock - module end-block
|
2019-06-26 09:03:25 -07:00
|
|
|
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
EndBlocker(ctx, am.keeper)
|
|
|
|
return []abci.ValidatorUpdate{}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|