cosmos-sdk/x/auth/module.go

112 lines
2.6 KiB
Go

package auth
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
_ sdk.AppModule = AppModule{}
_ sdk.AppModuleBasic = AppModuleBasic{}
)
// name of this module
const ModuleName = "auth"
// app module basics object
type AppModuleBasic struct{}
// module name
func (AppModuleBasic) Name() string {
return ModuleName
}
// register module codec
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {
RegisterCodec(cdc)
}
// default genesis state
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
return moduleCdc.MustMarshalJSON(DefaultGenesisState())
}
// module validate genesis
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var data GenesisState
err := moduleCdc.UnmarshalJSON(bz, &data)
if err != nil {
return err
}
return ValidateGenesis(data)
}
//___________________________
// app module object
type AppModule struct {
AppModuleBasic
accountKeeper AccountKeeper
feeCollectionKeeper FeeCollectionKeeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(accountKeeper AccountKeeper,
feeCollectionKeeper FeeCollectionKeeper) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: accountKeeper,
feeCollectionKeeper: feeCollectionKeeper,
}
}
// module name
func (AppModule) Name() string {
return ModuleName
}
// register invariants
func (AppModule) RegisterInvariants(_ sdk.InvariantRouter) {}
// module message route name
func (AppModule) Route() string { return "" }
// module handler
func (AppModule) NewHandler() sdk.Handler { return nil }
// module querier route name
func (AppModule) QuerierRoute() string {
return QuerierRoute
}
// module querier
func (am AppModule) NewQuerierHandler() sdk.Querier {
return NewQuerier(am.accountKeeper)
}
// module init-genesis
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
moduleCdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.accountKeeper, am.feeCollectionKeeper, genesisState)
return []abci.ValidatorUpdate{}
}
// module export genesis
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.accountKeeper, am.feeCollectionKeeper)
return moduleCdc.MustMarshalJSON(gs)
}
// module begin-block
func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) sdk.Tags {
return sdk.EmptyTags()
}
// module end-block
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, sdk.Tags) {
return []abci.ValidatorUpdate{}, sdk.EmptyTags()
}