2019-11-08 06:40:56 -08:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2020-06-06 00:59:57 -07:00
|
|
|
"github.com/gogo/protobuf/grpc"
|
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
|
|
|
// module codec
|
|
|
|
var moduleCdc = codec.New()
|
|
|
|
|
|
|
|
func init() {
|
2020-06-10 11:54:15 -07:00
|
|
|
types.RegisterCodec(moduleCdc)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterCodec registers the upgrade types on the amino codec
|
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
2020-06-10 11:54:15 -07:00
|
|
|
types.RegisterCodec(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
|
|
|
}
|
|
|
|
|
|
|
|
// 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-07-25 01:03:58 -07:00
|
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc codec.JSONMarshaler) sdk.Querier {
|
|
|
|
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.
|
|
|
|
func (am AppModule) RegisterQueryService(server grpc.Server) {
|
|
|
|
types.RegisterQueryServer(server, am.keeper)
|
|
|
|
}
|
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-02-18 04:50:13 -08:00
|
|
|
func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ 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{}
|
|
|
|
}
|