2019-05-16 08:25:32 -07:00
|
|
|
package genaccounts
|
|
|
|
|
|
|
|
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-07-22 08:26:42 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/exported"
|
2019-07-24 14:37:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
|
2019-05-16 08:25:32 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-08-13 15:16:03 -07:00
|
|
|
_ module.AppModuleGenesis = AppModule{}
|
|
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
_ module.AppModuleSimulation = AppModuleSimulation{}
|
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 genesis accounts module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModuleBasic struct{}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// Name returns the genesis accounts module's name.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) Name() string {
|
|
|
|
return ModuleName
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterCodec performs a no-op.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) {}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the genesis accounts
|
|
|
|
// module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) DefaultGenesis() json.RawMessage {
|
2019-07-22 08:26:42 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(GenesisState{})
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// ValidateGenesis performs genesis state validation for the genesis accounts module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
|
|
|
|
var data GenesisState
|
2019-07-22 08:26:42 -07:00
|
|
|
err := ModuleCdc.UnmarshalJSON(bz, &data)
|
2019-05-16 08:25:32 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ValidateGenesis(data)
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// RegisterRESTRoutes registers no REST routes for the genesis accounts module.
|
2019-06-06 08:43:15 -07:00
|
|
|
func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {}
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetTxCmd returns no root tx command for the genesis accounts module.
|
2019-06-05 16:26:17 -07:00
|
|
|
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// GetQueryCmd returns no root query command for the genesis accounts module.
|
2019-06-05 16:26:17 -07:00
|
|
|
func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil }
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
// extra function from sdk.AppModuleBasic
|
2019-08-13 15:16:03 -07:00
|
|
|
|
|
|
|
// IterateGenesisAccounts iterates over the genesis accounts and perform an operation at each of them
|
2019-05-16 08:25:32 -07:00
|
|
|
// - to used by other modules
|
|
|
|
func (AppModuleBasic) IterateGenesisAccounts(cdc *codec.Codec, appGenesis map[string]json.RawMessage,
|
2019-07-22 08:26:42 -07:00
|
|
|
iterateFn func(exported.Account) (stop bool)) {
|
2019-05-16 08:25:32 -07:00
|
|
|
|
|
|
|
genesisState := GetGenesisStateFromAppState(cdc, appGenesis)
|
2019-05-22 14:06:49 -07:00
|
|
|
for _, genAcc := range genesisState {
|
2019-05-16 08:25:32 -07:00
|
|
|
acc := genAcc.ToAccount()
|
|
|
|
if iterateFn(acc) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModuleSimulation defines the module simulation functions used by the genesis accounts module.
|
|
|
|
type AppModuleSimulation struct{}
|
|
|
|
|
|
|
|
// RegisterStoreDecoder performs a no-op.
|
|
|
|
func (AppModuleSimulation) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}
|
|
|
|
|
|
|
|
//____________________________________________________________________________
|
|
|
|
|
|
|
|
// AppModule implements an application module for the genesis accounts module.
|
2019-05-16 08:25:32 -07:00
|
|
|
type AppModule struct {
|
|
|
|
AppModuleBasic
|
2019-08-13 15:16:03 -07:00
|
|
|
AppModuleSimulation
|
|
|
|
|
2019-07-22 08:26:42 -07:00
|
|
|
accountKeeper types.AccountKeeper
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAppModule creates a new AppModule object
|
2019-07-22 08:26:42 -07:00
|
|
|
func NewAppModule(accountKeeper types.AccountKeeper) module.AppModule {
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-05 16:26:17 -07:00
|
|
|
return module.NewGenesisOnlyAppModule(AppModule{
|
2019-08-13 15:16:03 -07:00
|
|
|
AppModuleBasic: AppModuleBasic{},
|
|
|
|
AppModuleSimulation: AppModuleSimulation{},
|
|
|
|
accountKeeper: accountKeeper,
|
2019-05-16 08:25:32 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-13 15:16:03 -07:00
|
|
|
// InitGenesis performs genesis initialization for the genesis accounts module. It returns
|
|
|
|
// no validator updates.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate {
|
|
|
|
var genesisState GenesisState
|
2019-07-22 08:26:42 -07:00
|
|
|
ModuleCdc.MustUnmarshalJSON(data, &genesisState)
|
|
|
|
InitGenesis(ctx, ModuleCdc, 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 genesis accounts
|
|
|
|
// module.
|
2019-05-16 08:25:32 -07:00
|
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
|
|
|
|
gs := ExportGenesis(ctx, am.accountKeeper)
|
2019-07-22 08:26:42 -07:00
|
|
|
return ModuleCdc.MustMarshalJSON(gs)
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|