2020-04-24 15:20:34 +00:00
|
|
|
package incentive
|
|
|
|
|
|
|
|
import (
|
2023-03-21 22:47:21 +00:00
|
|
|
"context"
|
2020-04-24 15:20:34 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2020-04-30 14:23:41 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2020-04-24 15:20:34 +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-04-24 15:20:34 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2020-04-24 15:20:34 +00:00
|
|
|
"github.com/kava-labs/kava/x/incentive/client/cli"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-08 00:39:27 +00:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2020-04-24 15:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// AppModuleBasic defines the basic application module used by the incentive module.
|
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
|
|
|
// Name returns the incentive module's name.
|
|
|
|
func (AppModuleBasic) Name() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterLegacyAminoCodec register module codec
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
|
|
types.RegisterLegacyAminoCodec(cdc)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the incentive
|
|
|
|
// module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
|
|
gs := types.DefaultGenesisState()
|
|
|
|
return cdc.MustMarshalJSON(&gs)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ValidateGenesis performs genesis state validation for the incentive module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
2020-04-24 15:20:34 +00:00
|
|
|
var gs types.GenesisState
|
2022-01-08 00:39:27 +00:00
|
|
|
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
|
2020-04-24 15:20:34 +00:00
|
|
|
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)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the incentive module.
|
|
|
|
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
2023-03-21 22:47:21 +00:00
|
|
|
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
|
|
func (AppModule) ConsensusVersion() uint64 {
|
2022-12-22 01:08:16 +00:00
|
|
|
return 1
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// GetTxCmd returns the root tx command for the incentive module.
|
|
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
|
|
|
return cli.GetTxCmd()
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// GetQueryCmd returns no root query command for the incentive module.
|
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
|
|
return cli.GetQueryCmd()
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AppModule implements the sdk.AppModule interface.
|
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
keeper keeper.Keeper
|
|
|
|
accountKeeper types.AccountKeeper
|
|
|
|
bankKeeper types.BankKeeper
|
|
|
|
cdpKeeper types.CdpKeeper
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewAppModule(keeper keeper.Keeper, ak types.AccountKeeper, bk types.BankKeeper, ck types.CdpKeeper) AppModule {
|
2020-04-24 15:20:34 +00:00
|
|
|
return AppModule{
|
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
keeper: keeper,
|
2022-01-08 00:39:27 +00:00
|
|
|
accountKeeper: ak,
|
|
|
|
bankKeeper: bk,
|
|
|
|
cdpKeeper: ck,
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the incentive module's name.
|
|
|
|
func (AppModule) Name() string {
|
|
|
|
return types.ModuleName
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterInvariants registers the incentive module invariants.
|
|
|
|
func (am 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))
|
2023-03-21 22:47:21 +00:00
|
|
|
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InitGenesis performs genesis initialization for the incentive module. It returns no validator updates.
|
2022-01-08 00:39:27 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, am.cdpKeeper, genState)
|
2020-04-24 15:20:34 +00:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the incentive module
|
2022-01-08 00:39:27 +00:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
2020-04-24 15:20:34 +00:00
|
|
|
gs := ExportGenesis(ctx, am.keeper)
|
2022-01-08 00:39:27 +00:00
|
|
|
return cdc.MustMarshalJSON(&gs)
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BeginBlock returns the begin blocker for the incentive module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
2020-04-24 15:20:34 +00:00
|
|
|
BeginBlocker(ctx, am.keeper)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EndBlock returns the end blocker for the incentive module. It returns no validator updates.
|
|
|
|
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|