-
Notifications
You must be signed in to change notification settings - Fork 28
/
genesis.go
60 lines (51 loc) · 1.51 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
)
// InitGenesis initializes the tokenfactory module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
k.CreateModuleAccount(ctx)
if genState.Params.DenomCreationFee == nil {
genState.Params.DenomCreationFee = sdk.NewCoins()
}
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}
for _, genDenom := range genState.GetFactoryDenoms() {
creator, _, err := types.DeconstructDenom(genDenom.GetDenom())
if err != nil {
panic(err)
}
err = k.createDenomAfterValidation(ctx, creator, genDenom.GetDenom())
if err != nil {
panic(err)
}
err = k.setAuthorityMetadata(ctx, genDenom.GetDenom(), genDenom.GetAuthorityMetadata())
if err != nil {
panic(err)
}
}
}
// ExportGenesis returns the tokenfactory module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
genDenoms := []types.GenesisDenom{}
iterator := k.GetAllDenomsIterator(ctx)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
denom := string(iterator.Value())
authorityMetadata, err := k.GetAuthorityMetadata(ctx, denom)
if err != nil {
panic(err)
}
genDenoms = append(genDenoms, types.GenesisDenom{
Denom: denom,
AuthorityMetadata: authorityMetadata,
})
}
return &types.GenesisState{
FactoryDenoms: genDenoms,
Params: k.GetParams(ctx),
}
}