/
genesis.go
52 lines (47 loc) · 1.47 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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/merlinslair/merlin/x/pool-incentives/types"
)
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
k.SetParams(ctx, genState.Params)
k.SetLockableDurations(ctx, genState.LockableDurations)
if genState.DistrInfo == nil {
k.SetDistrInfo(ctx, types.DistrInfo{
TotalWeight: sdk.NewInt(0),
Records: nil,
})
} else {
k.SetDistrInfo(ctx, *genState.DistrInfo)
}
if genState.PoolToGauges != nil {
for _, record := range genState.PoolToGauges.PoolToGauge {
k.SetPoolGaugeId(ctx, record.PoolId, record.Duration, record.GaugeId)
}
}
}
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
distrInfo := k.GetDistrInfo(ctx)
lastPoolId := k.poolmanagerKeeper.GetNextPoolId(ctx)
lockableDurations := k.GetLockableDurations(ctx)
var poolToGauges types.PoolToGauges
for i := 1; i < int(lastPoolId); i++ {
for _, duration := range lockableDurations {
gaugeID, err := k.GetPoolGaugeId(ctx, uint64(i), duration)
if err != nil {
panic(err)
}
var poolToGauge types.PoolToGauge
poolToGauge.Duration = duration
poolToGauge.GaugeId = gaugeID
poolToGauge.PoolId = uint64(i)
poolToGauges.PoolToGauge = append(poolToGauges.PoolToGauge, poolToGauge)
}
}
return &types.GenesisState{
Params: k.GetParams(ctx),
LockableDurations: k.GetLockableDurations(ctx),
DistrInfo: &distrInfo,
PoolToGauges: &poolToGauges,
}
}