80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package consensus
|
|
|
|
import (
|
|
"context"
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"google.golang.org/grpc"
|
|
|
|
"cosmossdk.io/core/appmodule"
|
|
|
|
"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/types/module"
|
|
"github.com/cosmos/cosmos-sdk/x/consensus/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/consensus/types"
|
|
)
|
|
|
|
// ConsensusVersion defines the current x/consensus module consensus version.
|
|
const ConsensusVersion = 1
|
|
|
|
var (
|
|
_ module.AppModuleBasic = AppModule{}
|
|
|
|
_ appmodule.AppModule = AppModule{}
|
|
)
|
|
|
|
// AppModuleBasic defines the basic application module used by the consensus module.
|
|
type AppModuleBasic struct {
|
|
cdc codec.Codec
|
|
}
|
|
|
|
// Name returns the consensus module's name.
|
|
func (AppModuleBasic) Name() string { return types.ModuleName }
|
|
|
|
// RegisterLegacyAminoCodec registers the consensus module's types on the LegacyAmino codec.
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
types.RegisterLegacyAminoCodec(cdc)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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,
|
|
}
|
|
}
|
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|