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
|
|
|
|
2020-04-30 14:13:31 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/incentive/client/cli"
|
|
|
|
"github.com/0glabs/0g-chain/x/incentive/keeper"
|
|
|
|
"github.com/0glabs/0g-chain/x/incentive/types"
|
2020-04-24 15:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-01-08 00:39:27 +00:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
// _ module.AppModuleSimulation = AppModule{}
|
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
|
|
|
// LegacyQuerierHandler returns sdk.Querier.
|
|
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
|
|
return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
|
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) {}
|
|
|
|
|
|
|
|
// Route returns the message routing key for the incentive module.
|
2022-01-08 00:39:27 +00:00
|
|
|
func (am AppModule) Route() sdk.Route {
|
|
|
|
return sdk.Route{}
|
2020-04-24 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QuerierRoute returns the incentive module's querier route name.
|
|
|
|
func (AppModule) QuerierRoute() string {
|
|
|
|
return types.QuerierRoute
|
|
|
|
}
|
|
|
|
|
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{}
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// // RegisterStoreDecoder registers a decoder for incentive module's types
|
|
|
|
// func (AppModuleBasic) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
|
|
|
// sdr[types.StoreKey] = simulation.DecodeStore
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // GenerateGenesisState creates a randomized GenState of the incentive module
|
|
|
|
// func (AppModuleBasic) GenerateGenesisState(simState *module.SimulationState) {
|
|
|
|
// simulation.RandomizedGenState(simState)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // RandomizedParams creates randomized incentive param changes for the simulator.
|
|
|
|
// func (AppModuleBasic) RandomizedParams(r *rand.Rand) []sim.ParamChange {
|
|
|
|
// return simulation.ParamChanges(r)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // ProposalContents doesn't return any content functions for governance proposals.
|
|
|
|
// func (AppModuleBasic) ProposalContents(_ module.SimulationState) []sim.WeightedProposalContent {
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // WeightedOperations returns the all the incentive module operations with their respective weights.
|
|
|
|
// func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.WeightedOperation {
|
|
|
|
// return simulation.WeightedOperations(simState.AppParams, simState.Cdc, am.accountKeeper, am.supplyKeeper, am.keeper)
|
|
|
|
// }
|