-
Notifications
You must be signed in to change notification settings - Fork 44
/
genesis.go
93 lines (80 loc) · 2.22 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/desmos-labs/desmos/v2/x/profiles/types"
)
// ExportGenesis returns the GenesisState associated with the given context
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return types.NewGenesisState(
k.GetDTagTransferRequests(ctx),
k.GetAllRelationships(ctx),
k.GetAllUsersBlocks(ctx),
k.GetParams(ctx),
k.GetPort(ctx),
k.GetChainLinks(ctx),
k.GetApplicationLinks(ctx),
)
}
// InitGenesis initializes the chain state based on the given GenesisState
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) []abci.ValidatorUpdate {
// Initialize the module params
k.SetParams(ctx, data.Params)
// Initialize the Profiles
k.ak.IterateAccounts(ctx, func(account authtypes.AccountI) (stop bool) {
if profile, ok := (account).(*types.Profile); ok {
err := k.StoreProfile(ctx, profile)
if err != nil {
panic(err)
}
}
return false
})
// Store the transfer requests
for _, request := range data.DTagTransferRequests {
err := k.SaveDTagTransferRequest(ctx, request)
if err != nil {
panic(err)
}
}
// Store the relationships
for _, relationship := range data.Relationships {
err := k.SaveRelationship(ctx, relationship)
if err != nil {
panic(err)
}
}
// Store the user blocks
for _, userBlock := range data.Blocks {
err := k.SaveUserBlock(ctx, userBlock)
if err != nil {
panic(err)
}
}
k.SetPort(ctx, data.IBCPortID)
// Only try to bind to port if it is not already bound, since we may already own
// port capability from capability InitGenesis
if !k.IsBound(ctx, data.IBCPortID) {
// module binds to the port on InitChain
// and claims the returned capability
err := k.BindPort(ctx, data.IBCPortID)
if err != nil {
panic("could not claim port capability: " + err.Error())
}
}
for _, link := range data.ChainLinks {
err := k.SaveChainLink(ctx, link)
if err != nil {
panic(err)
}
}
// Store the application links
for _, link := range data.ApplicationLinks {
err := k.SaveApplicationLink(ctx, link)
if err != nil {
panic(err)
}
}
return nil
}