-
Notifications
You must be signed in to change notification settings - Fork 39
/
genesis.go
51 lines (43 loc) · 1.45 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
package keeper
import (
"sort"
sdk "github.com/cosmos/cosmos-sdk/types"
types "github.com/peggyjv/sommelier/v7/x/cork/types/v2"
)
// InitGenesis initialize default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, k Keeper, gs types.GenesisState) {
k.SetParams(ctx, gs.Params)
k.SetCellarIDs(ctx, gs.CellarIds)
k.SetLatestInvalidationNonce(ctx, gs.InvalidationNonce)
for _, corkResult := range gs.CorkResults {
k.SetCorkResult(ctx, corkResult.Cork.IDHash(corkResult.BlockHeight), *corkResult)
}
for _, scheduledCork := range gs.ScheduledCorks {
valAddr, err := sdk.ValAddressFromHex(scheduledCork.Validator)
if err != nil {
panic(err)
}
k.SetScheduledCork(ctx, scheduledCork.BlockHeight, valAddr, *scheduledCork.Cork)
}
}
// ExportGenesis writes the current store values
// to a genesis file, which can be imported again
// with InitGenesis
func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState {
var cellarIDSet types.CellarIDSet
existingCellarIDs := k.GetCellarIDs(ctx)
cellarIDs := make([]string, 0)
for _, id := range existingCellarIDs {
cellarIDs = append(cellarIDs, id.String())
}
sort.Strings(cellarIDs)
cellarIDSet.Ids = cellarIDs
return types.GenesisState{
Params: k.GetParamSet(ctx),
CellarIds: cellarIDSet,
InvalidationNonce: k.GetLatestInvalidationNonce(ctx),
ScheduledCorks: k.GetScheduledCorks(ctx),
CorkResults: k.GetCorkResults(ctx),
}
}