2019-11-08 06:40:56 -08:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
2020-09-04 01:24:19 -07:00
|
|
|
"context"
|
2019-11-08 06:40:56 -08:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2020-09-08 09:09:50 -07:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2019-11-08 06:40:56 -08:00
|
|
|
"github.com/spf13/cobra"
|
2020-01-16 13:46:51 -08:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2020-06-01 05:46:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-11-08 06:40:56 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-05-19 13:17:29 -07:00
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2019-11-08 06:40:56 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/client/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/client/rest"
|
2020-06-10 11:54:15 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
2019-11-08 06:40:56 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-09-07 07:47:12 -07:00
|
|
|
types.RegisterLegacyAminoCodec(codec.NewLegacyAmino())
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-07-23 19:45:34 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2019-11-08 06:40:56 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// AppModuleBasic implements the sdk.AppModuleBasic interface
|
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
|
|
|
// Name returns the ModuleName
|
|
|
|
func (AppModuleBasic) Name() string {
|
2020-06-10 11:54:15 -07:00
|
|
|
return types.ModuleName
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
2020-09-07 07:47:12 -07:00
|
|
|
// RegisterLegacyAminoCodec registers the upgrade types on the LegacyAmino codec
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
|
|
types.RegisterLegacyAminoCodec(cdc)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterRESTRoutes registers all REST query handlers
|
2020-06-01 05:46:03 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router) {
|
|
|
|
rest.RegisterRoutes(clientCtx, r)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
2020-08-25 08:44:13 -07:00
|
|
|
// RegisterGRPCRoutes registers the gRPC Gateway routes for the upgrade module.
|
2020-09-04 01:24:19 -07:00
|
|
|
func (AppModuleBasic) RegisterGRPCRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
|
|
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
|
|
}
|
2020-08-25 08:44:13 -07:00
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
2020-07-08 15:00:56 -07:00
|
|
|
return cli.GetQueryCmd()
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTxCmd returns the transaction commands for this module
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
2020-07-08 15:00:56 -07:00
|
|
|
return cli.GetTxCmd()
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
2020-07-23 19:45:34 -07:00
|
|
|
func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
2020-05-19 13:17:29 -07:00
|
|
|
types.RegisterInterfaces(registry)
|
|
|
|
}
|
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
// AppModule implements the sdk.AppModule interface
|
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2020-06-10 11:54:15 -07:00
|
|
|
keeper keeper.Keeper
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2020-06-10 11:54:15 -07:00
|
|
|
func NewAppModule(keeper keeper.Keeper) AppModule {
|
2019-11-08 06:40:56 -08:00
|
|
|
return AppModule{
|
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterInvariants does nothing, there are no invariants to enforce
|
|
|
|
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
|
|
|
|
|
|
|
// Route is empty, as we do not handle Messages (just proposals)
|
2020-06-11 08:37:23 -07:00
|
|
|
func (AppModule) Route() sdk.Route { return sdk.Route{} }
|
2019-11-08 06:40:56 -08:00
|
|
|
|
|
|
|
// QuerierRoute returns the route we respond to for abci queries
|
2020-06-10 11:54:15 -07:00
|
|
|
func (AppModule) QuerierRoute() string { return types.QuerierKey }
|
2019-11-08 06:40:56 -08:00
|
|
|
|
2020-07-24 12:04:29 -07:00
|
|
|
// LegacyQuerierHandler registers a query handler to respond to the module-specific queries
|
2020-08-26 02:39:38 -07:00
|
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
2020-07-25 01:03:58 -07:00
|
|
|
return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
2020-07-20 06:09:57 -07:00
|
|
|
// RegisterQueryService registers a GRPC query service to respond to the
|
|
|
|
// module-specific GRPC queries.
|
2020-10-12 09:31:51 -07:00
|
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
|
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
2020-07-20 06:09:57 -07:00
|
|
|
}
|
2020-06-06 00:59:57 -07:00
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
// InitGenesis is ignored, no sense in serializing future upgrades
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate {
|
2019-11-08 06:40:56 -08:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultGenesis is an empty object
|
2020-02-18 04:50:13 -08:00
|
|
|
func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage {
|
2019-11-08 06:40:56 -08:00
|
|
|
return []byte("{}")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis is always successful, as we ignore the value
|
2020-07-25 01:10:04 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, config client.TxEncodingConfig, _ json.RawMessage) error {
|
2019-11-08 06:40:56 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis is always empty, as InitGenesis does nothing either
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
|
|
|
|
return am.DefaultGenesis(cdc)
|
2019-11-08 06:40:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// BeginBlock calls the upgrade module hooks
|
|
|
|
//
|
|
|
|
// CONTRACT: this is registered in BeginBlocker *before* all other modules' BeginBlock functions
|
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {
|
|
|
|
BeginBlocker(am.keeper, ctx, req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EndBlock does nothing
|
|
|
|
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|