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