2019-11-08 06:40:56 -08:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"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-12-23 08:05:47 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
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-05-19 13:17:29 -07:00
|
|
|
types "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
2019-11-08 06:40:56 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// module codec
|
|
|
|
var moduleCdc = codec.New()
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterCodec(moduleCdc)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-05-19 13:17:29 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
_ module.InterfaceModule = 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 {
|
|
|
|
return ModuleName
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterCodec registers the upgrade types on the amino codec
|
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
|
|
|
|
RegisterCodec(cdc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
|
|
|
queryCmd := &cobra.Command{
|
|
|
|
Use: "upgrade",
|
|
|
|
Short: "Querying commands for the upgrade module",
|
|
|
|
}
|
2019-12-23 08:05:47 -08:00
|
|
|
queryCmd.AddCommand(flags.GetCommands(
|
2019-11-08 06:40:56 -08:00
|
|
|
cli.GetPlanCmd(StoreKey, cdc),
|
|
|
|
cli.GetAppliedHeightCmd(StoreKey, cdc),
|
|
|
|
)...)
|
|
|
|
|
|
|
|
return queryCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTxCmd returns the transaction commands for this module
|
2020-06-01 05:46:03 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd(_ client.Context) *cobra.Command {
|
2019-11-08 06:40:56 -08:00
|
|
|
txCmd := &cobra.Command{
|
|
|
|
Use: "upgrade",
|
|
|
|
Short: "Upgrade transaction subcommands",
|
|
|
|
}
|
2020-05-27 08:39:59 -07:00
|
|
|
txCmd.AddCommand(flags.PostCommands()...)
|
2019-11-08 06:40:56 -08:00
|
|
|
return txCmd
|
|
|
|
}
|
|
|
|
|
2020-05-19 13:17:29 -07:00
|
|
|
func (b AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) {
|
|
|
|
types.RegisterInterfaces(registry)
|
|
|
|
}
|
|
|
|
|
2019-11-08 06:40:56 -08:00
|
|
|
// AppModule implements the sdk.AppModule interface
|
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
keeper Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
|
|
|
func NewAppModule(keeper Keeper) AppModule {
|
|
|
|
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)
|
|
|
|
func (AppModule) Route() string { return "" }
|
|
|
|
|
|
|
|
// NewHandler is empty, as we do not handle Messages (just proposals)
|
|
|
|
func (am AppModule) NewHandler() sdk.Handler { return nil }
|
|
|
|
|
|
|
|
// QuerierRoute returns the route we respond to for abci queries
|
|
|
|
func (AppModule) QuerierRoute() string { return QuerierKey }
|
|
|
|
|
|
|
|
// NewQuerierHandler registers a query handler to respond to the module-specific queries
|
|
|
|
func (am AppModule) NewQuerierHandler() sdk.Querier {
|
|
|
|
return NewQuerier(am.keeper)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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{}
|
|
|
|
}
|