-
Notifications
You must be signed in to change notification settings - Fork 30
/
migrate.go
44 lines (36 loc) · 1.64 KB
/
migrate.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
package v043
import (
"github.com/Finschia/finschia-sdk/client"
v040bank "github.com/Finschia/finschia-sdk/x/bank/legacy/v040"
v043bank "github.com/Finschia/finschia-sdk/x/bank/legacy/v043"
bank "github.com/Finschia/finschia-sdk/x/bank/types"
"github.com/Finschia/finschia-sdk/x/genutil/types"
v040gov "github.com/Finschia/finschia-sdk/x/gov/legacy/v040"
v043gov "github.com/Finschia/finschia-sdk/x/gov/legacy/v043"
gov "github.com/Finschia/finschia-sdk/x/gov/types"
)
// Migrate migrates exported state from v0.40 to a v0.43 genesis state.
func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
// Migrate x/gov.
if appState[v040gov.ModuleName] != nil {
// unmarshal relative source genesis application state
var oldGovState gov.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appState[v040gov.ModuleName], &oldGovState)
// delete deprecated x/gov genesis state
delete(appState, v040gov.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v043gov.ModuleName] = clientCtx.Codec.MustMarshalJSON(v043gov.MigrateJSON(&oldGovState))
}
if appState[v040bank.ModuleName] != nil {
// unmarshal relative source genesis application state
var oldBankState bank.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appState[v040bank.ModuleName], &oldBankState)
// delete deprecated x/bank genesis state
delete(appState, v040bank.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v043bank.ModuleName] = clientCtx.Codec.MustMarshalJSON(v043bank.MigrateJSON(&oldBankState))
}
return appState
}