2018-11-08 16:28:28 -08:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-06-17 11:42:27 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
2020-05-20 12:21:00 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
2018-11-08 16:28:28 -08:00
|
|
|
)
|
|
|
|
|
2019-02-08 13:35:19 -08:00
|
|
|
// InitGenesis - Init store state from genesis data
|
2019-06-28 13:11:27 -07:00
|
|
|
//
|
|
|
|
// CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through
|
|
|
|
// a genesis port script to the new fee collector account
|
2020-06-17 11:42:27 -07:00
|
|
|
func InitGenesis(ctx sdk.Context, ak keeper.AccountKeeper, data types.GenesisState) {
|
2018-12-20 11:09:43 -08:00
|
|
|
ak.SetParams(ctx, data.Params)
|
2019-09-12 12:22:25 -07:00
|
|
|
|
2020-07-29 09:00:15 -07:00
|
|
|
accounts, err := types.UnpackAccounts(data.Accounts)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
accounts = types.SanitizeGenesisAccounts(accounts)
|
|
|
|
|
|
|
|
for _, a := range accounts {
|
2019-09-12 12:22:25 -07:00
|
|
|
acc := ak.NewAccount(ctx, a)
|
|
|
|
ak.SetAccount(ctx, acc)
|
|
|
|
}
|
2020-03-05 13:11:05 -08:00
|
|
|
|
2020-06-17 11:42:27 -07:00
|
|
|
ak.GetModuleAccount(ctx, types.FeeCollectorName)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis returns a GenesisState for a given context and keeper
|
2020-08-11 07:22:30 -07:00
|
|
|
func ExportGenesis(ctx sdk.Context, ak keeper.AccountKeeper) *types.GenesisState {
|
2018-12-20 11:09:43 -08:00
|
|
|
params := ak.GetParams(ctx)
|
2019-09-12 12:22:25 -07:00
|
|
|
|
2020-05-20 12:21:00 -07:00
|
|
|
var genAccounts types.GenesisAccounts
|
|
|
|
ak.IterateAccounts(ctx, func(account types.AccountI) bool {
|
|
|
|
genAccount := account.(types.GenesisAccount)
|
2019-09-12 12:22:25 -07:00
|
|
|
genAccounts = append(genAccounts, genAccount)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2020-06-17 11:42:27 -07:00
|
|
|
return types.NewGenesisState(params, genAccounts)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|