Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
154 lines
4.6 KiB
Go
154 lines
4.6 KiB
Go
package epochs
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"google.golang.org/grpc"
|
|
|
|
"cosmossdk.io/core/appmodule"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/client"
|
|
"git.cw.tr/mukan-network/mukan-sdk/codec"
|
|
codectypes "git.cw.tr/mukan-network/mukan-sdk/codec/types"
|
|
sdk "git.cw.tr/mukan-network/mukan-sdk/types"
|
|
"git.cw.tr/mukan-network/mukan-sdk/types/module"
|
|
simtypes "git.cw.tr/mukan-network/mukan-sdk/types/simulation"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/epochs/keeper"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/epochs/simulation"
|
|
"git.cw.tr/mukan-network/mukan-sdk/x/epochs/types"
|
|
)
|
|
|
|
var (
|
|
_ module.AppModuleSimulation = AppModule{}
|
|
_ module.HasGenesis = AppModule{}
|
|
|
|
_ appmodule.AppModule = AppModule{}
|
|
_ appmodule.HasBeginBlocker = AppModule{}
|
|
)
|
|
|
|
const ConsensusVersion = 1
|
|
|
|
// AppModule implements the AppModule interface for the epochs module.
|
|
type AppModule struct {
|
|
keeper keeper.Keeper
|
|
}
|
|
|
|
// NewAppModule creates a new AppModule object.
|
|
func NewAppModule(keeper keeper.Keeper) AppModule {
|
|
return AppModule{
|
|
keeper: keeper,
|
|
}
|
|
}
|
|
|
|
// IsAppModule implements the appmodule.AppModule interface.
|
|
func (am AppModule) IsAppModule() {}
|
|
|
|
// Name returns the epochs module's name.
|
|
//
|
|
// Deprecated: kept for legacy reasons.
|
|
func (AppModule) Name() string {
|
|
return types.ModuleName
|
|
}
|
|
|
|
// RegisterLegacyAminoCodec registers the epochs module's types for the given codec.
|
|
func (AppModule) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}
|
|
|
|
func (AppModule) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the epochs module.
|
|
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
|
|
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// RegisterServices registers module services.
|
|
func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error {
|
|
types.RegisterQueryServer(registrar, keeper.NewQuerier(am.keeper))
|
|
return nil
|
|
}
|
|
|
|
// DefaultGenesis returns the epochs module's default genesis state.
|
|
func (am AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
data, err := cdc.MarshalJSON(types.DefaultGenesis())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return data
|
|
}
|
|
|
|
// ValidateGenesis performs genesis state validation for the epochs module.
|
|
func (am AppModule) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
|
|
var gs types.GenesisState
|
|
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
|
}
|
|
|
|
return gs.Validate()
|
|
}
|
|
|
|
// InitGenesis performs the epochs module's genesis initialization
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) {
|
|
var gs types.GenesisState
|
|
err := cdc.UnmarshalJSON(bz, &gs)
|
|
if err != nil {
|
|
panic(fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err))
|
|
}
|
|
|
|
if err := am.keeper.InitGenesis(ctx, gs); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// ExportGenesis returns the epochs module's exported genesis state as raw JSON bytes.
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
gs, err := am.keeper.ExportGenesis(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
bz, err := cdc.MarshalJSON(gs)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return bz
|
|
}
|
|
|
|
// ConsensusVersion implements HasConsensusVersion
|
|
func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion }
|
|
|
|
// BeginBlock executes all ABCI BeginBlock logic respective to the epochs module.
|
|
func (am AppModule) BeginBlock(ctx context.Context) error {
|
|
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
|
return am.keeper.BeginBlocker(sdkCtx)
|
|
}
|
|
|
|
// AppModuleSimulation functions
|
|
|
|
// WeightedOperations is a no-op.
|
|
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
|
|
return nil
|
|
}
|
|
|
|
// GenerateGenesisState creates a randomized GenState of the epochs module.
|
|
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
|
simulation.RandomizedGenState(simState)
|
|
}
|
|
|
|
// RegisterStoreDecoder registers a decoder for epochs module's types
|
|
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
|
|
sdr[types.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema)
|
|
}
|
|
|
|
// TODO add when we have collections full support with schema
|
|
/*
|
|
// ModuleCodec implements schema.HasModuleCodec.
|
|
// It allows the indexer to decode the module's KVPairUpdate.
|
|
func (am AppModule) ModuleCodec() (schema.ModuleCodec, error) {
|
|
return am.keeper.Schema.ModuleCodec(collections.IndexingOptions{})
|
|
}
|
|
*/
|