2020-03-10 22:29:16 +00:00
|
|
|
package committee
|
|
|
|
|
|
|
|
import (
|
2022-01-08 00:39:27 +00:00
|
|
|
"context"
|
2020-03-10 22:29:16 +00:00
|
|
|
"encoding/json"
|
2022-01-08 00:39:27 +00:00
|
|
|
"fmt"
|
2020-03-10 22:29:16 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2020-03-10 22:29:16 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-03-10 22:29:16 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2022-01-08 00:39:27 +00:00
|
|
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2020-03-10 22:29:16 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2020-03-13 23:13:42 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/committee/client/cli"
|
2020-03-14 01:16:45 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/client/rest"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
2020-03-10 22:29:16 +00:00
|
|
|
)
|
|
|
|
|
2022-09-01 20:20:37 +00:00
|
|
|
// ConsensusVersion defines the current module consensus version.
|
|
|
|
const ConsensusVersion = 1
|
|
|
|
|
2020-03-10 22:29:16 +00:00
|
|
|
var (
|
2022-01-08 00:39:27 +00:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
// _ module.AppModuleSimulation = AppModule{}
|
2020-03-10 22:29:16 +00:00
|
|
|
)
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// AppModuleBasic
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-03-10 22:29:16 +00:00
|
|
|
// AppModuleBasic app module basics object
|
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Name get module name
|
2020-03-10 22:29:16 +00:00
|
|
|
func (AppModuleBasic) Name() string {
|
2022-01-08 00:39:27 +00:00
|
|
|
return types.ModuleName
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Registers legacy amino codec
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
|
|
types.RegisterLegacyAminoCodec(cdc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterInterfaces registers the module's interface types
|
|
|
|
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
|
|
|
|
types.RegisterInterfaces(reg)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultGenesis default genesis state
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
|
|
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis module validate genesis
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
|
|
|
var genState types.GenesisState
|
|
|
|
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
2020-03-11 19:27:36 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return genState.Validate()
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterRESTRoutes registers committee module's REST service handlers.
|
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
|
|
|
rest.RegisterRoutes(clientCtx, rtr)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for committee module.
|
|
|
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
|
|
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// GetTxCmd returns committee module's root tx command.
|
|
|
|
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
|
|
|
|
return cli.GetTxCmd()
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// GetQueryCmd returns committee module's root query command.
|
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
|
|
return cli.GetQueryCmd()
|
|
|
|
}
|
2020-03-10 22:29:16 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// AppModule
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// AppModule implements the AppModule interface for committee module.
|
2020-03-10 22:29:16 +00:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
keeper keeper.Keeper
|
|
|
|
accountKeeper types.AccountKeeper
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewAppModule(keeper keeper.Keeper, accountKeeper types.AccountKeeper) AppModule {
|
2020-03-10 22:29:16 +00:00
|
|
|
return AppModule{
|
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
2020-04-27 18:19:05 +00:00
|
|
|
accountKeeper: accountKeeper,
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Name returns committee module's name.
|
|
|
|
func (am AppModule) Name() string {
|
|
|
|
return am.AppModuleBasic.Name()
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Route returns committee module's message route.
|
|
|
|
func (am AppModule) Route() sdk.Route { return sdk.Route{} }
|
2020-03-10 22:29:16 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// QuerierRoute returns committee module's query routing key.
|
|
|
|
func (AppModule) QuerierRoute() string { return types.QuerierRoute }
|
2020-03-10 22:29:16 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// LegacyQuerierHandler returns committee module's Querier.
|
|
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
|
|
return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterServices registers a GRPC query service to respond to the
|
|
|
|
// module-specific GRPC queries.
|
|
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
|
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
|
|
|
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterInvariants registers committee module's invariants.
|
|
|
|
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
2020-03-10 22:29:16 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// InitGenesis performs committee module's genesis initialization It returns
|
|
|
|
// no validator updates.
|
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
|
|
|
|
var genState types.GenesisState
|
|
|
|
cdc.MustUnmarshalJSON(gs, &genState)
|
|
|
|
InitGenesis(ctx, am.keeper, &genState)
|
2020-03-10 22:29:16 +00:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ExportGenesis returns committee module's exported genesis state as raw JSON bytes.
|
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
|
|
genState := ExportGenesis(ctx, am.keeper)
|
|
|
|
return cdc.MustMarshalJSON(genState)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ConsensusVersion implements ConsensusVersion.
|
2022-09-01 20:20:37 +00:00
|
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
// BeginBlock executes all ABCI BeginBlock logic respective to committee module.
|
2020-03-10 22:29:16 +00:00
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
2020-03-12 17:05:40 +00:00
|
|
|
BeginBlocker(ctx, req, am.keeper)
|
2020-03-10 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// EndBlock executes all ABCI EndBlock logic respective to committee module. It
|
|
|
|
// returns no validator updates.
|
2020-03-10 22:29:16 +00:00
|
|
|
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
2020-04-27 18:19:05 +00:00
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// // GenerateGenesisState creates a randomized GenState of the auction module
|
|
|
|
// func (AppModuleBasic) GenerateGenesisState(simState *module.SimulationState) {
|
|
|
|
// simulation.RandomizedGenState(simState)
|
|
|
|
// }
|
2020-04-27 18:19:05 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// // ProposalContents doesn't return any content functions for governance proposals.
|
|
|
|
// func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
|
|
|
|
// return simulation.ProposalContents(am.keeper, simState.ParamChanges)
|
|
|
|
// }
|
2020-04-27 18:19:05 +00:00
|
|
|
|
2020-05-04 21:17:20 +00:00
|
|
|
// RandomizedParams returns functions that generate params for the module
|
2022-01-08 00:39:27 +00:00
|
|
|
// func (AppModuleBasic) RandomizedParams(r *rand.Rand) []sim.ParamChange {
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // RegisterStoreDecoder registers a decoder for the module's types
|
|
|
|
// func (AppModuleBasic) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
|
|
|
// sdr[StoreKey] = simulation.DecodeStore
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // WeightedOperations returns the module operations for use in simulations
|
|
|
|
// func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.WeightedOperation {
|
|
|
|
// return simulation.WeightedOperations(simState.AppParams, simState.Cdc, am.accountKeeper, am.keeper, simState.Contents)
|
|
|
|
// }
|