77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
|
package genutil
|
||
|
|
||
|
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.AppModuleGenesis = AppModule{}
|
||
|
_ sdk.AppModuleBasic = AppModuleBasic{}
|
||
|
)
|
||
|
|
||
|
// module name
|
||
|
const ModuleName = "genutil"
|
||
|
|
||
|
// app module basics object
|
||
|
type AppModuleBasic struct{}
|
||
|
|
||
|
// module name
|
||
|
func (AppModuleBasic) Name() string {
|
||
|
return ModuleName
|
||
|
}
|
||
|
|
||
|
// register module codec
|
||
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
|
||
|
|
||
|
// default genesis state
|
||
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
||
|
return moduleCdc.MustMarshalJSON(GenesisState{})
|
||
|
}
|
||
|
|
||
|
// 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
|
||
|
type AppModule struct {
|
||
|
AppModuleBasic
|
||
|
accountKeeper AccountKeeper
|
||
|
stakingKeeper StakingKeeper
|
||
|
deliverTx deliverTxfn
|
||
|
}
|
||
|
|
||
|
// NewAppModule creates a new AppModule object
|
||
|
func NewAppModule(accountKeeper AccountKeeper,
|
||
|
stakingKeeper StakingKeeper, deliverTx deliverTxfn) sdk.AppModule {
|
||
|
|
||
|
return sdk.NewGenesisOnlyAppModule(AppModule{
|
||
|
AppModuleBasic: AppModuleBasic{},
|
||
|
accountKeeper: accountKeeper,
|
||
|
stakingKeeper: stakingKeeper,
|
||
|
deliverTx: deliverTx,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
// module init-genesis
|
||
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
||
|
var genesisState GenesisState
|
||
|
moduleCdc.MustUnmarshalJSON(data, &genesisState)
|
||
|
return InitGenesis(ctx, moduleCdc, am.stakingKeeper, am.deliverTx, genesisState)
|
||
|
}
|
||
|
|
||
|
// module export genesis
|
||
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
||
|
return nil
|
||
|
}
|