Skip to content

Commit

Permalink
AppModuleGenesis seperation
Browse files Browse the repository at this point in the history
int
  • Loading branch information
rigelrozanski committed May 13, 2019
1 parent 5c0aa05 commit a45a6f3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 65 deletions.
52 changes: 47 additions & 5 deletions types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ func (mbm ModuleBasicManager) ValidateGenesis(genesis map[string]json.RawMessage
}

//_________________________________________________________
// AppModuleGenesis is the standard form for an application module genesis functions
type AppModuleGenesis interface {
AppModuleBasic
InitGenesis(Context, json.RawMessage) []abci.ValidatorUpdate
ExportGenesis(Context) json.RawMessage
}

// AppModule is the standard form for an application module
type AppModule interface {
AppModuleBasic
AppModuleGenesis

// registers
RegisterInvariants(InvariantRouter)
Expand All @@ -91,14 +98,49 @@ type AppModule interface {
QuerierRoute() string
NewQuerierHandler() Querier

// genesis
InitGenesis(Context, json.RawMessage) []abci.ValidatorUpdate
ExportGenesis(Context) json.RawMessage

BeginBlock(Context, abci.RequestBeginBlock) Tags
EndBlock(Context, abci.RequestEndBlock) ([]abci.ValidatorUpdate, Tags)
}

//___________________________
// app module
type GenesisOnlyAppModule struct {
AppModuleGenesis
}

// NewGenesisOnlyAppModule creates a new GenesisOnlyAppModule object
func NewGenesisOnlyAppModule(amg AppModuleGenesis) AppModule {
return GenesisOnlyAppModule{
AppModuleGenesis: amg,
}
}

// register invariants
func (GenesisOnlyAppModule) RegisterInvariants(_ InvariantRouter) {}

// module message route ngame
func (GenesisOnlyAppModule) Route() string { return "" }

// module handler
func (GenesisOnlyAppModule) NewHandler() Handler { return nil }

// module querier route ngame
func (GenesisOnlyAppModule) QuerierRoute() string { return "" }

// module querier
func (gam GenesisOnlyAppModule) NewQuerierHandler() Querier { return nil }

// module begin-block
func (gam GenesisOnlyAppModule) BeginBlock(ctx Context, req abci.RequestBeginBlock) Tags {
return EmptyTags()
}

// module end-block
func (GenesisOnlyAppModule) EndBlock(_ Context, _ abci.RequestEndBlock) ([]abci.ValidatorUpdate, Tags) {
return []abci.ValidatorUpdate{}, EmptyTags()
}

//____________________________________________________________________________
// module manager provides the high level utility for managing and executing
// operations for a group of modules
type ModuleManager struct {
Expand Down
35 changes: 5 additions & 30 deletions x/genaccounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

var (
_ sdk.AppModule = AppModule{}
_ sdk.AppModuleBasic = AppModuleBasic{}
_ sdk.AppModuleGenesis = AppModule{}
_ sdk.AppModuleBasic = AppModuleBasic{}
)

// module name
Expand Down Expand Up @@ -66,29 +66,14 @@ type AppModule struct {
}

// NewAppModule creates a new AppModule object
func NewAppModule(accountKeeper AccountKeeper) AppModule {
func NewAppModule(accountKeeper AccountKeeper) sdk.AppModule {

return AppModule{
return sdk.NewGenesisOnlyAppModule(AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: accountKeeper,
}
})
}

// 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 "" }

// module querier
func (am AppModule) NewQuerierHandler() sdk.Querier { return nil }

// module init-genesis
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
Expand All @@ -102,13 +87,3 @@ func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
gs := ExportGenesis(ctx, am.accountKeeper)
return moduleCdc.MustMarshalJSON(gs)
}

// module begin-block
func (am AppModule) BeginBlock(ctx sdk.Context, req 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()
}
35 changes: 5 additions & 30 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

var (
_ sdk.AppModule = AppModule{}
_ sdk.AppModuleBasic = AppModuleBasic{}
_ sdk.AppModuleGenesis = AppModule{}
_ sdk.AppModuleBasic = AppModuleBasic{}
)

// module name
Expand Down Expand Up @@ -53,31 +53,16 @@ type AppModule struct {

// NewAppModule creates a new AppModule object
func NewAppModule(accountKeeper AccountKeeper,
stakingKeeper StakingKeeper, deliverTx deliverTxfn) AppModule {
stakingKeeper StakingKeeper, deliverTx deliverTxfn) sdk.AppModule {

return AppModule{
return sdk.NewGenesisOnlyAppModule(AppModule{
AppModuleBasic: AppModuleBasic{},
accountKeeper: accountKeeper,
stakingKeeper: stakingKeeper,
deliverTx: deliverTx,
}
})
}

// 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 "" }

// module querier
func (am AppModule) NewQuerierHandler() sdk.Querier { return nil }

// module init-genesis
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
Expand All @@ -89,13 +74,3 @@ func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.Va
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return nil
}

// module begin-block
func (am AppModule) BeginBlock(ctx sdk.Context, req 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()
}

0 comments on commit a45a6f3

Please sign in to comment.