-
Notifications
You must be signed in to change notification settings - Fork 50
/
genesis.go
49 lines (38 loc) · 1.33 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
package oracle
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/certikfoundation/shentu/x/oracle/keeper"
"github.com/certikfoundation/shentu/x/oracle/types"
)
// InitGenesis puts all data from genesis state into store.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
operators := data.Operators
totalCollateral := data.TotalCollateral
poolParams := data.PoolParams
taskParams := data.TaskParams
withdraws := data.Withdraws
tasks := data.Tasks
for _, operator := range operators {
k.SetOperator(ctx, operator)
}
k.SetTotalCollateral(ctx, totalCollateral)
k.SetLockedPoolParams(ctx, poolParams)
k.SetTaskParams(ctx, taskParams)
for _, withdraw := range withdraws {
withdraw.DueBlock += ctx.BlockHeight()
k.SetWithdraw(ctx, withdraw)
}
for _, task := range tasks {
k.UpdateAndSetTask(ctx, task)
}
}
// ExportGenesis extracts all data from store to genesis state.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
operators := k.GetAllOperators(ctx)
totalCollateral, _ := k.GetTotalCollateral(ctx)
poolParams := k.GetLockedPoolParams(ctx)
taskParams := k.GetTaskParams(ctx)
withdraws := k.GetAllWithdrawsForExport(ctx)
tasks := k.UpdateAndGetAllTasks(ctx)
return types.NewGenesisState(operators, totalCollateral, poolParams, taskParams, withdraws, tasks)
}