2020-12-21 17:18:55 +00:00
|
|
|
package hard
|
2020-09-21 21:08:43 +00:00
|
|
|
|
|
|
|
import (
|
2022-01-08 00:39:27 +00:00
|
|
|
"context"
|
2020-09-21 21:08:43 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2020-09-21 21:08:43 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-09-21 21:08:43 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2022-01-08 00:39:27 +00:00
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2020-09-21 21:08:43 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
2020-09-21 21:08:43 +00:00
|
|
|
|
2020-12-21 17:18:55 +00:00
|
|
|
"github.com/kava-labs/kava/x/hard/client/cli"
|
|
|
|
"github.com/kava-labs/kava/x/hard/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/hard/types"
|
2020-09-21 21:08:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-08 00:39:27 +00:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2020-09-21 21:08:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AppModuleBasic app module basics object
|
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
|
|
|
// Name get module name
|
|
|
|
func (AppModuleBasic) Name() string {
|
2022-01-08 00:39:27 +00:00
|
|
|
return types.ModuleName
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterLegacyAminoCodec register module codec
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
|
|
types.RegisterLegacyAminoCodec(cdc)
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the hard
|
|
|
|
// module.
|
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
|
|
gs := types.DefaultGenesisState()
|
|
|
|
return cdc.MustMarshalJSON(&gs)
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ValidateGenesis performs genesis state validation for the hard module.
|
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
|
|
|
var gs types.GenesisState
|
|
|
|
err := cdc.UnmarshalJSON(bz, &gs)
|
2020-09-21 21:08:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return gs.Validate()
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterInterfaces implements InterfaceModule.RegisterInterfaces
|
|
|
|
func (a AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|
|
|
types.RegisterInterfaces(registry)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module.
|
|
|
|
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
|
|
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
|
|
func (AppModule) ConsensusVersion() uint64 {
|
|
|
|
return 1
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 17:18:55 +00:00
|
|
|
// GetTxCmd returns the root tx command for the hard module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
|
|
|
return cli.GetTxCmd()
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 17:18:55 +00:00
|
|
|
// GetQueryCmd returns no root query command for the hard module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
|
|
return cli.GetQueryCmd()
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModule app module type
|
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
keeper keeper.Keeper
|
|
|
|
accountKeeper types.AccountKeeper
|
|
|
|
bankKeeper types.BankKeeper
|
2020-10-30 09:59:47 +00:00
|
|
|
pricefeedKeeper types.PricefeedKeeper
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewAppModule(keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, pricefeedKeeper types.PricefeedKeeper) AppModule {
|
2020-09-21 21:08:43 +00:00
|
|
|
return AppModule{
|
2020-10-30 09:59:47 +00:00
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
2022-01-08 00:39:27 +00:00
|
|
|
accountKeeper: accountKeeper,
|
|
|
|
bankKeeper: bankKeeper,
|
2020-10-30 09:59:47 +00:00
|
|
|
pricefeedKeeper: pricefeedKeeper,
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name module name
|
|
|
|
func (AppModule) Name() string {
|
2022-01-08 00:39:27 +00:00
|
|
|
return types.ModuleName
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterInvariants register module invariants
|
|
|
|
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterServices registers module services.
|
|
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
|
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
|
|
|
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper, am.accountKeeper, am.bankKeeper))
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// InitGenesis performs genesis initialization for the hard module. It returns
|
|
|
|
// no validator updates.
|
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
|
|
|
|
var genState types.GenesisState
|
|
|
|
// Initialize global index to index in genesis state
|
|
|
|
cdc.MustUnmarshalJSON(gs, &genState)
|
2020-09-21 21:08:43 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
InitGenesis(ctx, am.keeper, am.accountKeeper, genState)
|
2020-09-21 21:08:43 +00:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the hard
|
|
|
|
// module.
|
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
2020-09-21 21:08:43 +00:00
|
|
|
gs := ExportGenesis(ctx, am.keeper)
|
2022-01-08 00:39:27 +00:00
|
|
|
return cdc.MustMarshalJSON(&gs)
|
2020-09-21 21:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BeginBlock module begin-block
|
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
|
|
|
BeginBlocker(ctx, am.keeper)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EndBlock module end-block
|
|
|
|
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|