github.com/Finschia/finschia-sdk@v0.49.1/x/auth/genesis.go (about)

     1  package auth
     2  
     3  import (
     4  	sdk "github.com/Finschia/finschia-sdk/types"
     5  	"github.com/Finschia/finschia-sdk/x/auth/keeper"
     6  	"github.com/Finschia/finschia-sdk/x/auth/types"
     7  )
     8  
     9  // InitGenesis - Init store state from genesis data
    10  //
    11  // CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through
    12  // a genesis port script to the new fee collector account
    13  func InitGenesis(ctx sdk.Context, ak keeper.AccountKeeper, data types.GenesisState) {
    14  	ak.SetParams(ctx, data.Params)
    15  
    16  	accounts, err := types.UnpackAccounts(data.Accounts)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	accounts = types.SanitizeGenesisAccounts(accounts)
    21  
    22  	for _, a := range accounts {
    23  		acc := ak.NewAccount(ctx, a)
    24  		ak.SetAccount(ctx, acc)
    25  	}
    26  
    27  	ak.GetModuleAccount(ctx, types.FeeCollectorName)
    28  }
    29  
    30  // ExportGenesis returns a GenesisState for a given context and keeper
    31  func ExportGenesis(ctx sdk.Context, ak keeper.AccountKeeper) *types.GenesisState {
    32  	params := ak.GetParams(ctx)
    33  
    34  	var genAccounts types.GenesisAccounts
    35  	ak.IterateAccounts(ctx, func(account types.AccountI) bool {
    36  		genAccount := account.(types.GenesisAccount)
    37  		genAccounts = append(genAccounts, genAccount)
    38  		return false
    39  	})
    40  
    41  	return types.NewGenesisState(params, genAccounts)
    42  }