-
Notifications
You must be signed in to change notification settings - Fork 40
/
genesis.go
42 lines (34 loc) · 1 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
package session
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sentinel-official/hub/v12/x/session/keeper"
"github.com/sentinel-official/hub/v12/x/session/types"
)
func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) {
k.SetParams(ctx, state.Params)
for _, item := range state.Sessions {
var (
accAddr = item.GetAddress()
nodeAddr = item.GetNodeAddress()
)
k.SetSession(ctx, item)
k.SetSessionForAccount(ctx, accAddr, item.ID)
k.SetSessionForNode(ctx, nodeAddr, item.ID)
k.SetSessionForSubscription(ctx, item.SubscriptionID, item.ID)
k.SetSessionForAllocation(ctx, item.SubscriptionID, accAddr, item.ID)
k.SetSessionForInactiveAt(ctx, item.InactiveAt, item.ID)
}
count := uint64(0)
for _, item := range state.Sessions {
if item.ID > count {
count = item.ID
}
}
k.SetCount(ctx, count)
}
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return types.NewGenesisState(
k.GetSessions(ctx),
k.GetParams(ctx),
)
}