cosmos-sdk/x/upgrade/module.go

140 lines
4.5 KiB
Go
Raw Normal View History

2019-11-08 06:40:56 -08:00
package upgrade
import (
"context"
2019-11-08 06:40:56 -08:00
"encoding/json"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
2019-11-08 06:40:56 -08:00
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/client"
2019-11-08 06:40:56 -08:00
"github.com/cosmos/cosmos-sdk/codec"
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/keeper"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
2019-11-08 06:40:56 -08:00
)
func init() {
types.RegisterLegacyAminoCodec(codec.NewLegacyAmino())
2019-11-08 06:40:56 -08:00
}
var (
_ 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 {
return types.ModuleName
2019-11-08 06:40:56 -08: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
}
feat!: remove legacy REST (#9594) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description ref: #7517 * [x] Remove the x/{module}/client/rest folder * [x] Remove all glue code between simapp/modules and the REST server <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - see #9615 - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [x] reviewed API design and naming - [ ] reviewed documentation is accurate - see #9615 - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-07-06 03:04:54 -07:00
// RegisterRESTRoutes registers the REST routes for the upgrade module.
// Deprecated: RegisterRESTRoutes is deprecated. `x/upgrade` legacy REST implementation
// has been removed from the SDK.
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {}
2019-11-08 06:40:56 -08:00
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
fix: Check error for RegisterQueryHandlerClient in all modules RegisterGRPCGatewayRoutes (#10439) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #10437 Checks the error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes` --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-10-28 04:01:25 -07:00
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}
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 {
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 {
return cli.GetTxCmd()
2019-11-08 06:40:56 -08:00
}
func (b AppModuleBasic) RegisterInterfaces(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.Keeper
2019-11-08 06:40:56 -08:00
}
// NewAppModule creates a new AppModule object
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) {}
feat!: remove legacy handler (#9650) <!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #7517 ref: [comment](https://github.com/cosmos/cosmos-sdk/pull/9594#issuecomment-872859821) <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
2021-07-19 07:49:42 -07:00
// Deprecated: Route returns the message routing key for the upgrade module.
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
func (AppModule) QuerierRoute() string { return types.QuerierKey }
2019-11-08 06:40:56 -08:00
// LegacyQuerierHandler registers a query handler to respond to the module-specific queries
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
2019-11-08 06:40:56 -08:00
}
[docs]: update building modules section to reflect ADR31 (#7702) * Revert "Revert "Update old ref of RegisterQueryService"" This reverts commit 03e4c56de53938ccbf025a441e54b9842f7c4544. * Update intro, module-manager and messages-and-queries * Update messages-and-queries * Update handler * Update structure * Add doc related to RegisterMsgServiceDesc * Update docs/building-modules/handler.md Co-authored-by: Robert Zaremba <robert@zaremba.ch> * Update docs/building-modules/handler.md Co-authored-by: Robert Zaremba <robert@zaremba.ch> * Update docs/building-modules/handler.md Co-authored-by: Robert Zaremba <robert@zaremba.ch> * Update docs/building-modules/messages-and-queries.md * Update handler.md * Rename handler.md to msg-services.md * Update legacy msgs wording * Update messages-and-queries.md * Update docs/building-modules/msg-services.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Update docs/building-modules/intro.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Remove handler mention from intro.md * Update docs/building-modules/messages-and-queries.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Update docs/building-modules/msg-services.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Update docs/building-modules/keeper.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Update docs/building-modules/msg-services.md Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> * Address review comments * Use tag * Update docs/building-modules/intro.md Co-authored-by: Cory <cjlevinson@gmail.com> * Update docs/building-modules/intro.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/core/transactions.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Remove framework related explanation from docs * Update docs/building-modules/messages-and-queries.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/module-manager.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/module-manager.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/building-modules/msg-services.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/core/baseapp.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/core/baseapp.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update beginblock-endblock.md * Update docs/core/baseapp.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Update docs/core/transactions.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Add deprecated notice * Update tx-lifecycle.md Co-authored-by: Robert Zaremba <robert@zaremba.ch> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Cory <cjlevinson@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-11-17 12:41:43 -08:00
// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}
2019-11-08 06:40:56 -08:00
// InitGenesis is ignored, no sense in serializing future upgrades
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate {
2019-11-08 06:40:56 -08:00
return []abci.ValidatorUpdate{}
}
// DefaultGenesis is an empty object
func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage {
2019-11-08 06:40:56 -08:00
return []byte("{}")
}
// ValidateGenesis is always successful, as we ignore the value
func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, 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
func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage {
return am.DefaultGenesis(cdc)
2019-11-08 06:40:56 -08:00
}
// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
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{}
}