-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis.go
70 lines (58 loc) · 2.36 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
package client
import (
"fmt"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/02-client/keeper"
"github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/02-client/types"
"github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/exported"
)
// InitGenesis initializes the ibc client submodule's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
k.SetParams(ctx, gs.Params)
// Set all client metadata first. This will allow client keeper to overwrite client and consensus state keys
// if clients accidentally write to ClientKeeper reserved keys.
if len(gs.ClientsMetadata) != 0 {
k.SetAllClientMetadata(ctx, gs.ClientsMetadata)
}
for _, client := range gs.Clients {
cs, ok := client.ClientState.GetCachedValue().(exported.ClientState)
if !ok {
panic("invalid client state")
}
if !gs.Params.IsAllowedClient(cs.ClientType()) {
panic(fmt.Sprintf("client state type %s is not registered on the allowlist", cs.ClientType()))
}
k.SetClientState(ctx, client.ClientId, cs)
}
for _, cs := range gs.ClientsConsensus {
for _, consState := range cs.ConsensusStates {
consensusState, ok := consState.ConsensusState.GetCachedValue().(exported.ConsensusState)
if !ok {
panic(fmt.Sprintf("invalid consensus state with client ID %s at height %s", cs.ClientId, consState.Height))
}
k.SetClientConsensusState(ctx, cs.ClientId, consState.Height, consensusState)
}
}
k.SetNextClientSequence(ctx, gs.NextClientSequence)
// NOTE: localhost creation is specifically disallowed for the time being.
// Issue: https://github.com/cosmos/cosmos-sdk/issues/7871
}
// ExportGenesis returns the ibc client submodule's exported genesis.
// NOTE: CreateLocalhost should always be false on export since a
// created localhost will be included in the exported clients.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
genClients := k.GetAllGenesisClients(ctx)
clientsMetadata, err := k.GetAllClientMetadata(ctx, genClients)
if err != nil {
panic(err)
}
return types.GenesisState{
Clients: genClients,
ClientsMetadata: clientsMetadata,
ClientsConsensus: k.GetAllConsensusStates(ctx),
Params: k.GetParams(ctx),
CreateLocalhost: false,
NextClientSequence: k.GetNextClientSequence(ctx),
}
}