-
Notifications
You must be signed in to change notification settings - Fork 117
/
genesis.go
72 lines (62 loc) · 1.8 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
package oracle
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/Sifchain/sifnode/x/oracle/keeper"
"github.com/Sifchain/sifnode/x/oracle/types"
)
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data types.GenesisState) (res []abci.ValidatorUpdate) {
if data.AddressWhitelist != nil {
wl := make([]sdk.ValAddress, 0, len(data.AddressWhitelist))
for i := range data.AddressWhitelist {
entry := data.AddressWhitelist[i]
if len(strings.TrimSpace(entry)) == 0 {
continue
}
wlAddress, err := sdk.ValAddressFromBech32(entry)
if err != nil {
panic(err)
}
wl = append(wl, wlAddress)
}
keeper.SetOracleWhiteList(ctx, wl)
}
if len(strings.TrimSpace(data.AdminAddress)) != 0 {
adminAddress, err := sdk.AccAddressFromBech32(data.AdminAddress)
if err != nil {
panic(err)
}
keeper.SetAdminAccount(ctx, adminAddress)
}
for _, dbProphecy := range data.Prophecies {
keeper.SetDBProphecy(ctx, *dbProphecy)
}
return []abci.ValidatorUpdate{}
}
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
whiteList := keeper.GetOracleWhiteList(ctx)
wl := make([]string, len(whiteList))
for i, entry := range whiteList {
wl[i] = entry.String()
}
adminAcc := keeper.GetAdminAccount(ctx)
prophecies := keeper.GetProphecies(ctx)
dbProphecies := make([]*types.DBProphecy, len(prophecies))
for i, p := range prophecies {
dbProphecy, err := p.SerializeForDB()
if err != nil {
panic(err)
}
dbProphecies[i] = &dbProphecy
}
return &types.GenesisState{
AddressWhitelist: wl,
AdminAddress: adminAcc.String(),
Prophecies: dbProphecies,
}
}
// ValidateGenesis validates the oracle genesis parameters
func ValidateGenesis(_ *types.GenesisState) error {
return nil
}