## Description fix various linting issues --- ### 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/main/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/main/docs/docs/building-modules) * [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/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)
180 lines
5.2 KiB
Go
180 lines
5.2 KiB
Go
package consensus
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
|
|
"cosmossdk.io/core/appmodule"
|
|
"cosmossdk.io/core/event"
|
|
"cosmossdk.io/depinject"
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"github.com/spf13/cobra"
|
|
"google.golang.org/grpc"
|
|
|
|
storetypes "cosmossdk.io/core/store"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
"github.com/cosmos/cosmos-sdk/runtime"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
"github.com/cosmos/cosmos-sdk/x/consensus/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/consensus/types"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
)
|
|
|
|
// ConsensusVersion defines the current x/consensus module consensus version.
|
|
const ConsensusVersion = 1
|
|
|
|
var (
|
|
_ module.AppModule = AppModule{}
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
)
|
|
|
|
// AppModuleBasic defines the basic application module used by the consensus_param module.
|
|
type AppModuleBasic struct {
|
|
cdc codec.Codec
|
|
}
|
|
|
|
// Name returns the consensus_param module's name.
|
|
func (AppModuleBasic) Name() string { return types.ModuleName }
|
|
|
|
// RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec.
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
types.RegisterLegacyAminoCodec(cdc)
|
|
}
|
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the consensus_param
|
|
// module.
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
// nil is returned since default genesis of consensus params is handled by tendermint
|
|
return nil
|
|
}
|
|
|
|
// ValidateGenesis performs genesis state validation
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
|
return nil
|
|
}
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
|
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
|
|
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// GetTxCmd returns the root tx command
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
|
return nil
|
|
}
|
|
|
|
// GetQueryCmd returns no root query command
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
return nil
|
|
}
|
|
|
|
// RegisterInterfaces registers interfaces and implementations of the bank module.
|
|
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|
types.RegisterInterfaces(registry)
|
|
}
|
|
|
|
// AppModule implements an application module
|
|
type AppModule struct {
|
|
AppModuleBasic
|
|
|
|
keeper keeper.Keeper
|
|
}
|
|
|
|
var (
|
|
_ appmodule.AppModule = AppModule{}
|
|
_ appmodule.HasServices = AppModule{}
|
|
)
|
|
|
|
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
|
|
func (am AppModule) IsOnePerModuleType() {}
|
|
|
|
// IsAppModule implements the appmodule.AppModule interface.
|
|
func (am AppModule) IsAppModule() {}
|
|
|
|
// RegisterServices registers module services.
|
|
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
|
types.RegisterMsgServer(registrar, am.keeper)
|
|
types.RegisterQueryServer(registrar, am.keeper)
|
|
return nil
|
|
}
|
|
|
|
// NewAppModule creates a new AppModule object
|
|
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
|
|
return AppModule{
|
|
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
|
keeper: keeper,
|
|
}
|
|
}
|
|
|
|
// Name returns the consensus_param module's name.
|
|
func (AppModule) Name() string { return types.ModuleName }
|
|
|
|
// InitGenesis is handled by for init genesis of consensus_param
|
|
func (am AppModule) InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate {
|
|
// nil is returned since initgenesis of consensus params is handled by tendermint
|
|
return nil
|
|
}
|
|
|
|
// ExportGenesis is handled by CometBFT export of genesis
|
|
func (am AppModule) ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage {
|
|
// nil is returned since ExportGenesis of consensus params is handled by CometBFT and baseapp
|
|
return nil
|
|
}
|
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|
|
|
|
func init() {
|
|
appmodule.Register(
|
|
&modulev1.Module{},
|
|
appmodule.Provide(ProvideModule),
|
|
)
|
|
}
|
|
|
|
type ModuleInputs struct {
|
|
depinject.In
|
|
|
|
Config *modulev1.Module
|
|
Cdc codec.Codec
|
|
StoreService storetypes.KVStoreService
|
|
EventManager event.Service
|
|
}
|
|
|
|
type ModuleOutputs struct {
|
|
depinject.Out
|
|
|
|
Keeper keeper.Keeper
|
|
Module appmodule.AppModule
|
|
BaseAppOption runtime.BaseAppOption
|
|
}
|
|
|
|
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
|
// default to governance authority if not provided
|
|
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
|
|
if in.Config.Authority != "" {
|
|
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
|
|
}
|
|
|
|
k := keeper.NewKeeper(in.Cdc, in.StoreService, authority.String(), in.EventManager)
|
|
m := NewAppModule(in.Cdc, k)
|
|
baseappOpt := func(app *baseapp.BaseApp) {
|
|
app.SetParamStore(k.ParamsStore)
|
|
}
|
|
|
|
return ModuleOutputs{
|
|
Keeper: k,
|
|
Module: m,
|
|
BaseAppOption: baseappOpt,
|
|
}
|
|
}
|