2024-02-01 04:48:40 +00:00
|
|
|
package module
|
|
|
|
|
2024-02-01 10:58:34 +00:00
|
|
|
import (
|
2024-02-02 09:39:10 +00:00
|
|
|
"context"
|
2024-02-01 10:58:34 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"cosmossdk.io/core/appmodule"
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
|
|
|
|
"git.vdb.to/cerc-io/laconic2d/x/bond"
|
|
|
|
"git.vdb.to/cerc-io/laconic2d/x/bond/keeper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-02-02 09:39:10 +00:00
|
|
|
_ module.AppModuleBasic = AppModule{}
|
|
|
|
_ appmodule.AppModule = AppModule{}
|
|
|
|
_ module.HasGenesis = AppModule{}
|
|
|
|
_ module.HasServices = AppModule{}
|
|
|
|
_ module.HasConsensusVersion = AppModule{}
|
2024-02-01 10:58:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConsensusVersion defines the current module consensus version
|
|
|
|
const ConsensusVersion = 1
|
|
|
|
|
|
|
|
type AppModule struct {
|
|
|
|
cdc codec.Codec
|
2024-02-28 04:34:58 +00:00
|
|
|
keeper *keeper.Keeper
|
2024-02-01 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2024-02-28 04:34:58 +00:00
|
|
|
func NewAppModule(cdc codec.Codec, keeper *keeper.Keeper) AppModule {
|
2024-02-01 10:58:34 +00:00
|
|
|
return AppModule{
|
|
|
|
cdc: cdc,
|
|
|
|
keeper: keeper,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAppModuleBasic(m AppModule) module.AppModuleBasic {
|
|
|
|
return module.CoreAppModuleBasicAdaptor(m.Name(), m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// module.AppModuleBasic
|
|
|
|
|
|
|
|
// Name returns the bond module's name.
|
|
|
|
func (AppModule) Name() string { return bond.ModuleName }
|
|
|
|
|
|
|
|
// RegisterLegacyAminoCodec registers the bond module's types on the LegacyAmino codec.
|
|
|
|
// New modules do not need to support Amino.
|
2024-02-02 09:39:10 +00:00
|
|
|
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
2024-02-01 10:58:34 +00:00
|
|
|
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bond module.
|
|
|
|
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
|
2024-02-02 09:39:10 +00:00
|
|
|
if err := bond.RegisterQueryHandlerClient(context.Background(), mux, bond.NewQueryClient(clientCtx)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-02-01 10:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterInterfaces registers interfaces and implementations of the bond module.
|
|
|
|
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|
|
|
bond.RegisterInterfaces(registry)
|
|
|
|
}
|
|
|
|
|
2024-02-02 09:39:10 +00:00
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|
|
|
|
|
2024-02-01 10:58:34 +00:00
|
|
|
// module.HasGenesis
|
|
|
|
|
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the module.
|
|
|
|
func (AppModule) DefaultGenesis(jsonCodec codec.JSONCodec) json.RawMessage {
|
|
|
|
return jsonCodec.MustMarshalJSON(bond.DefaultGenesisState())
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis performs genesis state validation for the module.
|
|
|
|
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
|
|
|
|
var data bond.GenesisState
|
|
|
|
if err := cdc.UnmarshalJSON(message, &data); err != nil {
|
|
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", bond.ModuleName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.Validate()
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitGenesis performs genesis initialization for the checkers module.
|
|
|
|
// It returns no validator updates.
|
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
|
|
|
|
var genesisState bond.GenesisState
|
|
|
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
|
|
|
|
|
|
|
if err := am.keeper.InitGenesis(ctx, &genesisState); err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to initialize %s genesis state: %v", bond.ModuleName, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the circuit
|
|
|
|
// module.
|
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
|
|
gs, err := am.keeper.ExportGenesis(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to export %s genesis state: %v", bond.ModuleName, err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return cdc.MustMarshalJSON(gs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// module.HasServices
|
|
|
|
|
|
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
|
// Register servers
|
2024-02-02 09:39:10 +00:00
|
|
|
bond.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
|
|
|
bond.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
2024-02-01 04:48:40 +00:00
|
|
|
}
|