-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
83 lines (77 loc) · 2.49 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
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2024 NASD Inc.
//
// Use of this source code is governed by a BSL-style
// license that can be found in the LICENSE file or at
// https://mariadb.com/bsl11.
package halo
import (
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/noble-assets/halo/v3/keeper"
"github.com/noble-assets/halo/v3/types"
"github.com/noble-assets/halo/v3/types/aggregator"
"github.com/noble-assets/halo/v3/types/entitlements"
)
func InitGenesis(ctx sdk.Context, k *keeper.Keeper, cdc address.Codec, genesis types.GenesisState) {
if err := k.SetAggregatorOwner(ctx, genesis.AggregatorState.Owner); err != nil {
panic(err)
}
if err := k.SetLastRoundId(ctx, genesis.AggregatorState.LastRoundId); err != nil {
panic(err)
}
if err := k.SetNextPrice(ctx, genesis.AggregatorState.NextPrice); err != nil {
panic(err)
}
for id, round := range genesis.AggregatorState.Rounds {
if err := k.SetRound(ctx, id, round); err != nil {
panic(err)
}
}
if err := k.SetEntitlementsOwner(ctx, genesis.EntitlementsState.Owner); err != nil {
panic(err)
}
for method, enabled := range genesis.EntitlementsState.PublicCapabilities {
if err := k.SetPublicCapability(ctx, method, enabled); err != nil {
panic(err)
}
}
for _, entry := range genesis.EntitlementsState.RoleCapabilities {
if err := k.SetRoleCapability(ctx, entry.Method, entry.Role, entry.Enabled); err != nil {
panic(err)
}
}
for _, entry := range genesis.EntitlementsState.UserRoles {
user, _ := cdc.StringToBytes(entry.User)
if err := k.SetUserRole(ctx, user, entry.Role, entry.Enabled); err != nil {
panic(err)
}
}
if err := k.SetOwner(ctx, genesis.Owner); err != nil {
panic(err)
}
for account, nonce := range genesis.Nonces {
address, _ := cdc.StringToBytes(account)
if err := k.SetNonce(ctx, address, nonce); err != nil {
panic(err)
}
}
}
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
AggregatorState: aggregator.GenesisState{
Owner: k.GetAggregatorOwner(ctx),
LastRoundId: k.GetLastRoundId(ctx),
NextPrice: k.GetNextPrice(ctx),
Rounds: k.GetRounds(ctx),
},
EntitlementsState: entitlements.GenesisState{
Owner: k.GetEntitlementsOwner(ctx),
Paused: k.GetPaused(ctx),
PublicCapabilities: k.GetPublicCapabilities(ctx),
RoleCapabilities: k.GetAllCapabilityRoles(ctx),
UserRoles: k.GetAllUserRoles(ctx),
},
Owner: k.GetOwner(ctx),
Nonces: k.GetNonces(ctx),
}
}