2019-05-16 08:25:32 -07:00
|
|
|
package mint
|
|
|
|
|
|
|
|
import (
|
2020-09-04 09:48:46 -07:00
|
|
|
"context"
|
2019-05-16 08:25:32 -07:00
|
|
|
"encoding/json"
|
2020-01-09 12:14:23 -08:00
|
|
|
"fmt"
|
2019-08-28 07:58:25 -07:00
|
|
|
"math/rand"
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
2020-08-25 08:44:13 -07:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
2020-06-01 05:46:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-05-16 08:25:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-07-23 19:45:34 -07:00
|
|
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2020-03-23 04:55:44 -07:00
|
|
|
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/client/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/client/rest"
|
2020-06-12 17:26:19 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
|
2019-08-13 15:16:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/simulation"
|
2020-04-20 08:22:12 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-08-13 15:16:03 -07:00
|
|
|
_ module.AppModule = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2019-12-05 01:29:54 -08:00
|
|
|
_ module.AppModuleSimulation = AppModule{}
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// AppModuleBasic defines the basic application module used by the mint module.
|
2020-04-21 14:33:56 -07:00
|
|
|
type AppModuleBasic struct {
|
|
|
|
cdc codec.Marshaler
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the mint module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
2020-06-12 17:26:19 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-09-07 07:47:12 -07:00
|
|
|
// RegisterLegacyAminoCodec registers the mint module's types on the given LegacyAmino codec.
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2020-07-23 19:45:34 -07:00
|
|
|
// RegisterInterfaces registers the module's interface types
|
|
|
|
func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the mint
|
|
|
|
// module.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage {
|
2020-06-12 17:26:19 -07:00
|
|
|
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// ValidateGenesis performs genesis state validation for the mint module.
|
2020-07-25 01:10:04 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error {
|
2020-06-12 17:26:19 -07:00
|
|
|
var data types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
2020-06-12 17:26:19 -07:00
|
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2020-01-09 12:14:23 -08:00
|
|
|
|
2020-06-12 17:26:19 -07:00
|
|
|
return types.ValidateGenesis(data)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterRESTRoutes registers the REST routes for the mint module.
|
2020-06-01 05:46:03 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
|
|
|
rest.RegisterRoutes(clientCtx, rtr)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2020-10-28 04:39:49 -07:00
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module.
|
|
|
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
2020-09-04 09:48:46 -07:00
|
|
|
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
|
|
|
2020-08-25 08:44:13 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetTxCmd returns no root tx command for the mint module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetQueryCmd returns the root query command for the mint module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
2020-07-19 03:16:57 -07:00
|
|
|
return cli.GetQueryCmd()
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// AppModule implements an application module for the mint module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-08-13 15:16:03 -07:00
|
|
|
|
2020-06-12 17:26:19 -07:00
|
|
|
keeper keeper.Keeper
|
2020-04-20 12:32:10 -07:00
|
|
|
authKeeper types.AccountKeeper
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2020-06-12 17:26:19 -07:00
|
|
|
func NewAppModule(cdc codec.Marshaler, keeper keeper.Keeper, ak types.AccountKeeper) AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
return AppModule{
|
2020-04-21 14:33:56 -07:00
|
|
|
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
2019-12-05 01:29:54 -08:00
|
|
|
keeper: keeper,
|
2020-04-20 12:32:10 -07:00
|
|
|
authKeeper: ak,
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the mint module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Name() string {
|
2020-06-12 17:26:19 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterInvariants registers the mint module invariants.
|
2019-06-06 13:32:38 -07:00
|
|
|
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Route returns the message routing key for the mint module.
|
2020-06-11 08:37:23 -07:00
|
|
|
func (AppModule) Route() sdk.Route { return sdk.Route{} }
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// QuerierRoute returns the mint module's querier route name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) QuerierRoute() string {
|
2020-06-12 17:26:19 -07:00
|
|
|
return types.QuerierRoute
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:04:29 -07:00
|
|
|
// LegacyQuerierHandler returns the mint module sdk.Querier.
|
2020-08-26 02:39:38 -07:00
|
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
2020-07-25 01:03:58 -07:00
|
|
|
return keeper.NewQuerier(am.keeper, legacyQuerierCdc)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-11-17 12:41:43 -08:00
|
|
|
// RegisterServices registers a gRPC query service to respond to the
|
2020-07-21 06:54:07 -07:00
|
|
|
// module-specific gRPC queries.
|
2020-10-12 09:31:51 -07:00
|
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
|
|
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
2020-07-21 06:54:07 -07:00
|
|
|
}
|
2020-06-06 00:59:57 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// InitGenesis performs genesis initialization for the mint module. It returns
|
|
|
|
// no validator updates.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
|
2020-06-12 17:26:19 -07:00
|
|
|
var genesisState types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
2020-03-05 02:45:51 -08:00
|
|
|
|
2020-08-11 07:22:30 -07:00
|
|
|
InitGenesis(ctx, am.keeper, am.authKeeper, &genesisState)
|
2019-05-16 08:25:32 -07:00
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the mint
|
|
|
|
// module.
|
2020-02-18 04:50:13 -08:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage {
|
2020-03-05 07:19:36 -08:00
|
|
|
gs := ExportGenesis(ctx, am.keeper)
|
2020-02-18 04:50:13 -08:00
|
|
|
return cdc.MustMarshalJSON(gs)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2021-02-10 09:49:31 -08:00
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
|
|
func (AppModule) ConsensusVersion() uint64 { return 1 }
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// BeginBlock returns the begin blocker for the mint module.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
2020-03-05 07:19:36 -08:00
|
|
|
BeginBlocker(ctx, am.keeper)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// EndBlock returns the end blocker for the mint module. It returns no validator
|
|
|
|
// updates.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
|
|
return []abci.ValidatorUpdate{}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2019-12-05 01:29:54 -08:00
|
|
|
|
|
|
|
// AppModuleSimulation functions
|
|
|
|
|
|
|
|
// GenerateGenesisState creates a randomized GenState of the mint module.
|
|
|
|
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
|
|
|
simulation.RandomizedGenState(simState)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProposalContents doesn't return any content functions for governance proposals.
|
2020-03-23 04:55:44 -07:00
|
|
|
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
|
2019-12-05 01:29:54 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RandomizedParams creates randomized mint param changes for the simulator.
|
2020-03-23 04:55:44 -07:00
|
|
|
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
|
2019-12-05 01:29:54 -08:00
|
|
|
return simulation.ParamChanges(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterStoreDecoder registers a decoder for mint module's types.
|
2020-04-21 14:33:56 -07:00
|
|
|
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
2020-06-12 17:26:19 -07:00
|
|
|
sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)
|
2019-12-05 01:29:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// WeightedOperations doesn't return any mint module operation.
|
2020-03-23 04:55:44 -07:00
|
|
|
func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
|
2019-12-05 01:29:54 -08:00
|
|
|
return nil
|
|
|
|
}
|