2018-11-08 16:28:28 -08:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-09-12 12:22:25 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/exported"
|
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
|
|
|
|
func InitGenesis(ctx sdk.Context, ak AccountKeeper, data GenesisState) {
|
2018-12-20 11:09:43 -08:00
|
|
|
ak.SetParams(ctx, data.Params)
|
2019-09-13 15:26:29 -07:00
|
|
|
data.Accounts = SanitizeGenesisAccounts(data.Accounts)
|
2019-09-12 12:22:25 -07:00
|
|
|
|
|
|
|
for _, a := range data.Accounts {
|
|
|
|
acc := ak.NewAccount(ctx, a)
|
|
|
|
ak.SetAccount(ctx, acc)
|
|
|
|
}
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExportGenesis returns a GenesisState for a given context and keeper
|
2019-06-28 13:11:27 -07:00
|
|
|
func ExportGenesis(ctx sdk.Context, ak AccountKeeper) GenesisState {
|
2018-12-20 11:09:43 -08:00
|
|
|
params := ak.GetParams(ctx)
|
2019-09-12 12:22:25 -07:00
|
|
|
|
2019-09-13 15:26:29 -07:00
|
|
|
var genAccounts exported.GenesisAccounts
|
2019-09-12 12:22:25 -07:00
|
|
|
ak.IterateAccounts(ctx, func(account exported.Account) bool {
|
|
|
|
genAccount := account.(exported.GenesisAccount)
|
|
|
|
genAccounts = append(genAccounts, genAccount)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
return NewGenesisState(params, genAccounts)
|
2018-11-08 16:28:28 -08:00
|
|
|
}
|