2019-05-16 08:25:32 -07:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
2020-09-04 01:24:19 -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
|
|
|
|
2020-08-25 08:44:13 -07:00
|
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
2020-06-06 00:59:57 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"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-06-17 11:42:27 -07:00
|
|
|
codectypes "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/auth/client/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
2020-06-17 11:42:27 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
2019-08-13 15:16:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
2020-06-17 11:42:27 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/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 auth module.
|
2020-05-20 12:21:00 -07:00
|
|
|
type AppModuleBasic struct{}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the auth module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
2020-06-17 11:42:27 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-09-07 07:47:12 -07:00
|
|
|
// RegisterLegacyAminoCodec registers the auth module's types for the given codec.
|
|
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
|
|
|
types.RegisterLegacyAminoCodec(cdc)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the auth
|
|
|
|
// module.
|
2021-04-29 03:46:22 -07:00
|
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
2020-06-17 11:42:27 -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 auth module.
|
2021-04-29 03:46:22 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
2020-06-17 11:42:27 -07:00
|
|
|
var data types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
|
2020-06-17 11:42:27 -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-17 11:42:27 -07:00
|
|
|
return types.ValidateGenesis(data)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterRESTRoutes registers the REST routes for the auth module.
|
2020-06-01 05:46:03 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
2020-06-17 11:42:27 -07:00
|
|
|
rest.RegisterRoutes(clientCtx, rtr, types.StoreKey)
|
2019-06-05 16:26:17 -07:00
|
|
|
}
|
|
|
|
|
2020-10-28 04:39:49 -07:00
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the auth module.
|
|
|
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
2021-02-23 00:46:01 -08:00
|
|
|
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-08-25 08:44:13 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetTxCmd returns the root tx command for the auth module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
2020-11-04 01:58:11 -08:00
|
|
|
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 auth module.
|
2020-07-21 08:28:43 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
2020-07-17 13:20:45 -07:00
|
|
|
return cli.GetQueryCmd()
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-07-23 19:45:34 -07:00
|
|
|
// RegisterInterfaces registers interfaces and implementations of the auth module.
|
|
|
|
func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
2020-06-17 11:42:27 -07:00
|
|
|
types.RegisterInterfaces(registry)
|
2020-05-20 12:21:00 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// AppModule implements an application module for the auth module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-08-13 15:16:03 -07:00
|
|
|
|
2020-08-24 03:55:42 -07:00
|
|
|
accountKeeper keeper.AccountKeeper
|
2020-10-23 05:07:52 -07:00
|
|
|
randGenAccountsFn types.RandomGenesisAccountsFn
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2021-04-29 03:46:22 -07:00
|
|
|
func NewAppModule(cdc codec.Codec, accountKeeper keeper.AccountKeeper, randGenAccountsFn types.RandomGenesisAccountsFn) AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
return AppModule{
|
2020-08-24 03:55:42 -07:00
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
accountKeeper: accountKeeper,
|
|
|
|
randGenAccountsFn: randGenAccountsFn,
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the auth module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) Name() string {
|
2020-06-17 11:42:27 -07:00
|
|
|
return types.ModuleName
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterInvariants performs a no-op.
|
2019-06-06 13:32:38 -07:00
|
|
|
func (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 auth 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 auth module's querier route name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModule) QuerierRoute() string {
|
2020-06-17 11:42:27 -07:00
|
|
|
return types.QuerierRoute
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:04:29 -07:00
|
|
|
// LegacyQuerierHandler returns the auth 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.accountKeeper, 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-20 06:09:57 -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.accountKeeper)
|
2021-04-08 08:20:29 -07:00
|
|
|
m := keeper.NewMigrator(am.accountKeeper, cfg.QueryServer())
|
|
|
|
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-07-21 10:48:37 -07:00
|
|
|
}
|
2020-06-06 00:59:57 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// InitGenesis performs genesis initialization for the auth module. It returns
|
|
|
|
// no validator updates.
|
2021-04-29 03:46:22 -07:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
2020-06-17 11:42:27 -07:00
|
|
|
var genesisState types.GenesisState
|
2020-02-18 04:50:13 -08:00
|
|
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
2020-04-20 12:32:10 -07:00
|
|
|
InitGenesis(ctx, am.accountKeeper, 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 auth
|
|
|
|
// module.
|
2021-04-29 03:46:22 -07:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
2019-06-28 13:11:27 -07:00
|
|
|
gs := ExportGenesis(ctx, am.accountKeeper)
|
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.
|
2021-04-08 08:20:29 -07:00
|
|
|
func (AppModule) ConsensusVersion() uint64 { return 2 }
|
2021-02-10 09:49:31 -08:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// BeginBlock returns the begin blocker for the auth module.
|
2019-06-26 09:03:25 -07:00
|
|
|
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// EndBlock returns the end blocker for the auth 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 auth module
|
2020-08-24 03:55:42 -07:00
|
|
|
func (am AppModule) GenerateGenesisState(simState *module.SimulationState) {
|
|
|
|
simulation.RandomizedGenState(simState, am.randGenAccountsFn)
|
2019-12-05 01:29:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 auth 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 auth module's types
|
2020-04-21 14:33:56 -07:00
|
|
|
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
|
2020-06-17 11:42:27 -07:00
|
|
|
sdr[types.StoreKey] = simulation.NewDecodeStore(am.accountKeeper)
|
2019-12-05 01:29:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// WeightedOperations doesn't return any auth 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
|
|
|
|
}
|