-
Notifications
You must be signed in to change notification settings - Fork 28
/
genesis.go
58 lines (52 loc) · 1.46 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
package farm
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irismod/modules/farm/keeper"
"github.com/irisnet/irismod/modules/farm/types"
)
// InitGenesis stores the genesis state
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
if err := types.ValidateGenesis(data); err != nil {
panic(err.Error())
}
for _, pool := range data.Pools {
for _, r := range pool.Rules {
k.SetRewardRule(ctx, pool.Id, r)
}
k.SetPool(ctx, pool)
if !k.Expired(ctx, pool) {
k.EnqueueActivePool(ctx, pool.Id, pool.EndHeight)
}
}
for _, farmInfo := range data.FarmInfos {
_, exist := k.GetPool(ctx, farmInfo.PoolId)
if !exist {
panic(types.ErrPoolNotFound)
}
k.SetFarmInfo(ctx, farmInfo)
}
for _, info := range data.Escrow {
k.SetEscrowInfo(ctx, info)
}
k.SetSequence(ctx, data.Sequence)
k.SetParams(ctx, data.Params)
}
// ExportGenesis outputs the genesis state
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
var pools []types.FarmPool
var farmInfos []types.FarmInfo
k.IteratorAllPools(ctx, func(pool types.FarmPool) {
pool.Rules = k.GetRewardRules(ctx, pool.Id)
pools = append(pools, pool)
})
k.IteratorAllFarmInfo(ctx, func(farmInfo types.FarmInfo) {
farmInfos = append(farmInfos, farmInfo)
})
return &types.GenesisState{
Params: k.GetParams(ctx),
Pools: pools,
FarmInfos: farmInfos,
Sequence: k.GetSequence(ctx),
Escrow: k.GetAllEscrowInfo(ctx),
}
}