99 lines
2.9 KiB
Go
99 lines
2.9 KiB
Go
package consensus
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"google.golang.org/grpc"
|
|
|
|
"cosmossdk.io/core/appmodule"
|
|
"cosmossdk.io/core/registry"
|
|
"cosmossdk.io/x/consensus/keeper"
|
|
"cosmossdk.io/x/consensus/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
)
|
|
|
|
// ConsensusVersion defines the current x/consensus module consensus version.
|
|
const ConsensusVersion = 1
|
|
|
|
var (
|
|
_ module.HasAminoCodec = AppModule{}
|
|
_ module.HasGRPCGateway = AppModule{}
|
|
|
|
_ appmodule.AppModule = AppModule{}
|
|
_ appmodule.HasGenesis = AppModule{}
|
|
_ appmodule.HasRegisterInterfaces = AppModule{}
|
|
)
|
|
|
|
// AppModule implements an application module
|
|
type AppModule struct {
|
|
cdc codec.Codec
|
|
keeper keeper.Keeper
|
|
}
|
|
|
|
// NewAppModule creates a new AppModule object
|
|
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
|
|
return AppModule{
|
|
cdc: cdc,
|
|
keeper: keeper,
|
|
}
|
|
}
|
|
|
|
// InitGenesis performs genesis initialization for the bank module.
|
|
func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error {
|
|
return am.keeper.InitGenesis(ctx)
|
|
}
|
|
|
|
// DefaultGenesis returns the default genesis state. (Noop)
|
|
func (am AppModule) DefaultGenesis() json.RawMessage {
|
|
return nil
|
|
}
|
|
|
|
// ValidateGenesis validates the genesis state. (Noop)
|
|
func (am AppModule) ValidateGenesis(data json.RawMessage) error {
|
|
return nil
|
|
}
|
|
|
|
// ExportGenesis returns the exported genesis state. (Noop)
|
|
func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
// IsAppModule implements the appmodule.AppModule interface.
|
|
func (AppModule) IsAppModule() {}
|
|
|
|
// Name returns the consensus module's name.
|
|
// Deprecated: kept for legacy reasons.
|
|
func (AppModule) Name() string { return types.ModuleName }
|
|
|
|
// RegisterLegacyAminoCodec registers the consensus module's types on the LegacyAmino codec.
|
|
func (AppModule) RegisterLegacyAminoCodec(registrar registry.AminoRegistrar) {
|
|
types.RegisterLegacyAminoCodec(registrar)
|
|
}
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes
|
|
func (AppModule) 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 (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) {
|
|
types.RegisterInterfaces(registrar)
|
|
}
|
|
|
|
// RegisterServices registers module services.
|
|
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
|
types.RegisterMsgServer(registrar, am.keeper)
|
|
types.RegisterQueryServer(registrar, am.keeper)
|
|
return nil
|
|
}
|
|
|
|
// ConsensusVersion implements HasConsensusVersion.
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|