/
genesis.go
39 lines (33 loc) · 1.06 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
package genaccounts
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)
// InitGenesis initializes accounts and deliver genesis transactions
func InitGenesis(ctx sdk.Context, _ *codec.Codec, accountKeeper types.AccountKeeper, genesisState GenesisState) {
genesisState.Sanitize()
// load the accounts
for _, gacc := range genesisState {
acc := gacc.ToAccount()
acc = accountKeeper.NewAccount(ctx, acc) // set account number
accountKeeper.SetAccount(ctx, acc)
}
}
// ExportGenesis exports genesis for all accounts
func ExportGenesis(ctx sdk.Context, accountKeeper types.AccountKeeper) GenesisState {
// iterate to get the accounts
accounts := []GenesisAccount{}
accountKeeper.IterateAccounts(ctx,
func(acc authexported.Account) (stop bool) {
account, err := NewGenesisAccountI(acc)
if err != nil {
panic(err)
}
accounts = append(accounts, account)
return false
},
)
return accounts
}