This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.go
200 lines (162 loc) · 8.14 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package v040
import (
"github.com/Pylons-tech/cosmos-sdk/client"
"github.com/Pylons-tech/cosmos-sdk/codec"
v039auth "github.com/Pylons-tech/cosmos-sdk/x/auth/migrations/v039"
v040auth "github.com/Pylons-tech/cosmos-sdk/x/auth/migrations/v040"
v036supply "github.com/Pylons-tech/cosmos-sdk/x/bank/migrations/v036"
v038bank "github.com/Pylons-tech/cosmos-sdk/x/bank/migrations/v038"
v040bank "github.com/Pylons-tech/cosmos-sdk/x/bank/migrations/v040"
v039crisis "github.com/Pylons-tech/cosmos-sdk/x/crisis/migrations/v039"
v040crisis "github.com/Pylons-tech/cosmos-sdk/x/crisis/migrations/v040"
v036distr "github.com/Pylons-tech/cosmos-sdk/x/distribution/migrations/v036"
v038distr "github.com/Pylons-tech/cosmos-sdk/x/distribution/migrations/v038"
v040distr "github.com/Pylons-tech/cosmos-sdk/x/distribution/migrations/v040"
v038evidence "github.com/Pylons-tech/cosmos-sdk/x/evidence/migrations/v038"
v040evidence "github.com/Pylons-tech/cosmos-sdk/x/evidence/migrations/v040"
v039genutil "github.com/Pylons-tech/cosmos-sdk/x/genutil/migrations/v039"
"github.com/Pylons-tech/cosmos-sdk/x/genutil/types"
v036gov "github.com/Pylons-tech/cosmos-sdk/x/gov/migrations/v036"
v040gov "github.com/Pylons-tech/cosmos-sdk/x/gov/migrations/v040"
v039mint "github.com/Pylons-tech/cosmos-sdk/x/mint/migrations/v039"
v040mint "github.com/Pylons-tech/cosmos-sdk/x/mint/migrations/v040"
v036params "github.com/Pylons-tech/cosmos-sdk/x/params/migrations/v036"
v039slashing "github.com/Pylons-tech/cosmos-sdk/x/slashing/migrations/v039"
v040slashing "github.com/Pylons-tech/cosmos-sdk/x/slashing/migrations/v040"
v038staking "github.com/Pylons-tech/cosmos-sdk/x/staking/migrations/v038"
v040staking "github.com/Pylons-tech/cosmos-sdk/x/staking/migrations/v040"
v038upgrade "github.com/Pylons-tech/cosmos-sdk/x/upgrade/migrations/v038"
)
func migrateGenutil(oldGenState v039genutil.GenesisState) *types.GenesisState {
return &types.GenesisState{
GenTxs: oldGenState.GenTxs,
}
}
// Migrate migrates exported state from v0.39 to a v0.40 genesis state.
func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
v039Codec := codec.NewLegacyAmino()
v039auth.RegisterLegacyAminoCodec(v039Codec)
v036gov.RegisterLegacyAminoCodec(v039Codec)
v036distr.RegisterLegacyAminoCodec(v039Codec)
v036params.RegisterLegacyAminoCodec(v039Codec)
v038upgrade.RegisterLegacyAminoCodec(v039Codec)
v040Codec := clientCtx.Codec
if appState[v038bank.ModuleName] != nil {
// unmarshal relative source genesis application state
var bankGenState v038bank.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &bankGenState)
// unmarshal x/auth genesis state to retrieve all account balances
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// unmarshal x/supply genesis state to retrieve total supply
var supplyGenState v036supply.GenesisState
v039Codec.MustUnmarshalJSON(appState[v036supply.ModuleName], &supplyGenState)
// delete deprecated x/bank genesis state
delete(appState, v038bank.ModuleName)
// delete deprecated x/supply genesis state
delete(appState, v036supply.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040bank.ModuleName] = v040Codec.MustMarshalJSON(v040bank.Migrate(bankGenState, authGenState, supplyGenState))
}
// remove balances from existing accounts
if appState[v039auth.ModuleName] != nil {
// unmarshal relative source genesis application state
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// delete deprecated x/auth genesis state
delete(appState, v039auth.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040auth.ModuleName] = v040Codec.MustMarshalJSON(v040auth.Migrate(authGenState))
}
// Migrate x/crisis.
if appState[v039crisis.ModuleName] != nil {
// unmarshal relative source genesis application state
var crisisGenState v039crisis.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039crisis.ModuleName], &crisisGenState)
// delete deprecated x/crisis genesis state
delete(appState, v039crisis.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040crisis.ModuleName] = v040Codec.MustMarshalJSON(v040crisis.Migrate(crisisGenState))
}
// Migrate x/distribution.
if appState[v038distr.ModuleName] != nil {
// unmarshal relative source genesis application state
var distributionGenState v038distr.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038distr.ModuleName], &distributionGenState)
// delete deprecated x/distribution genesis state
delete(appState, v038distr.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040distr.ModuleName] = v040Codec.MustMarshalJSON(v040distr.Migrate(distributionGenState))
}
// Migrate x/evidence.
if appState[v038evidence.ModuleName] != nil {
// unmarshal relative source genesis application state
var evidenceGenState v038evidence.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &evidenceGenState)
// delete deprecated x/evidence genesis state
delete(appState, v038evidence.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040evidence.ModuleName] = v040Codec.MustMarshalJSON(v040evidence.Migrate(evidenceGenState))
}
// Migrate x/gov.
if appState[v036gov.ModuleName] != nil {
// unmarshal relative source genesis application state
var govGenState v036gov.GenesisState
v039Codec.MustUnmarshalJSON(appState[v036gov.ModuleName], &govGenState)
// delete deprecated x/gov genesis state
delete(appState, v036gov.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040gov.ModuleName] = v040Codec.MustMarshalJSON(v040gov.Migrate(govGenState))
}
// Migrate x/mint.
if appState[v039mint.ModuleName] != nil {
// unmarshal relative source genesis application state
var mintGenState v039mint.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039mint.ModuleName], &mintGenState)
// delete deprecated x/mint genesis state
delete(appState, v039mint.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040mint.ModuleName] = v040Codec.MustMarshalJSON(v040mint.Migrate(mintGenState))
}
// Migrate x/slashing.
if appState[v039slashing.ModuleName] != nil {
// unmarshal relative source genesis application state
var slashingGenState v039slashing.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039slashing.ModuleName], &slashingGenState)
// delete deprecated x/slashing genesis state
delete(appState, v039slashing.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040slashing.ModuleName] = v040Codec.MustMarshalJSON(v040slashing.Migrate(slashingGenState))
}
// Migrate x/staking.
if appState[v038staking.ModuleName] != nil {
// unmarshal relative source genesis application state
var stakingGenState v038staking.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038staking.ModuleName], &stakingGenState)
// delete deprecated x/staking genesis state
delete(appState, v038staking.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040staking.ModuleName] = v040Codec.MustMarshalJSON(v040staking.Migrate(stakingGenState))
}
// Migrate x/genutil
if appState[v039genutil.ModuleName] != nil {
// unmarshal relative source genesis application state
var genutilGenState v039genutil.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039genutil.ModuleName], &genutilGenState)
// delete deprecated x/staking genesis state
delete(appState, v039genutil.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[ModuleName] = v040Codec.MustMarshalJSON(migrateGenutil(genutilGenState))
}
return appState
}