2019-05-16 08:25:32 -07:00
|
|
|
package genutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2019-05-16 08:25:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-06-05 16:26:17 -07:00
|
|
|
_ module.AppModuleGenesis = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
// register rest routes
|
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router, _ *codec.Codec) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the root tx command of this module
|
|
|
|
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }
|
|
|
|
|
|
|
|
// get the root query command of this module
|
|
|
|
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
//___________________________
|
|
|
|
// app module
|
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
|
|
|
accountKeeper AccountKeeper
|
|
|
|
stakingKeeper StakingKeeper
|
|
|
|
deliverTx deliverTxfn
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
|
|
|
func NewAppModule(accountKeeper AccountKeeper,
|
2019-06-05 16:26:17 -07:00
|
|
|
stakingKeeper StakingKeeper, deliverTx deliverTxfn) module.AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
return module.NewGenesisOnlyAppModule(AppModule{
|
2019-05-16 08:25:32 -07:00
|
|
|
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
|
|
|
|
}
|