-
Notifications
You must be signed in to change notification settings - Fork 563
/
genesis.go
42 lines (33 loc) · 1.32 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
package v7
import (
"github.com/cosmos/cosmos-sdk/codec"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
clientv7 "github.com/cosmos/ibc-go/v7/modules/core/02-client/migrations/v7"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/modules/core/types"
)
// MigrateGenesis accepts an exported IBC client genesis file and migrates it to:
//
// - Update solo machine client state protobuf definition (v2 to v3)
// - Remove all solo machine consensus states
// - Remove any localhost clients
func MigrateGenesis(appState genutiltypes.AppMap, cdc codec.ProtoCodecMarshaler) (genutiltypes.AppMap, error) {
if appState[ibcexported.ModuleName] == nil {
return appState, nil
}
// ensure legacy solo machines types are registered
clientv7.RegisterInterfaces(cdc.InterfaceRegistry())
// unmarshal old ibc genesis state
ibcGenState := &types.GenesisState{}
cdc.MustUnmarshalJSON(appState[ibcexported.ModuleName], ibcGenState)
clientGenState, err := clientv7.MigrateGenesis(&ibcGenState.ClientGenesis, cdc)
if err != nil {
return nil, err
}
ibcGenState.ClientGenesis = *clientGenState
// delete old genesis state
delete(appState, ibcexported.ModuleName)
// set new ibc genesis state
appState[ibcexported.ModuleName] = cdc.MustMarshalJSON(ibcGenState)
return appState, nil
}