-
Notifications
You must be signed in to change notification settings - Fork 1
/
upgrade.go
191 lines (178 loc) · 7.9 KB
/
upgrade.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
package app
import (
sdkmath "cosmossdk.io/math"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
sdkupgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts"
icacontrollertypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types"
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"
coinswaptypes "github.com/irisnet/irismod/modules/coinswap/types"
farmtypes "github.com/irisnet/irismod/modules/farm/types"
"github.com/irisnet/irismod/modules/htlc"
htlctypes "github.com/irisnet/irismod/modules/htlc/types"
mttypes "github.com/irisnet/irismod/modules/mt/types"
nftmodule "github.com/irisnet/irismod/modules/nft/module"
nfttypes "github.com/irisnet/irismod/modules/nft/types"
"github.com/irisnet/irismod/modules/oracle"
oracletypes "github.com/irisnet/irismod/modules/oracle/types"
"github.com/irisnet/irismod/modules/random"
randomtypes "github.com/irisnet/irismod/modules/random/types"
"github.com/irisnet/irismod/modules/record"
recordtypes "github.com/irisnet/irismod/modules/record/types"
"github.com/irisnet/irismod/modules/service"
servicetypes "github.com/irisnet/irismod/modules/service/types"
"github.com/irisnet/irismod/modules/token"
tokentypes "github.com/irisnet/irismod/modules/token/types"
tibcmttypes "github.com/bianjieai/tibc-go/modules/tibc/apps/mt_transfer/types"
tibcnfttypes "github.com/bianjieai/tibc-go/modules/tibc/apps/nft_transfer/types"
tibcclienttypes "github.com/bianjieai/tibc-go/modules/tibc/core/02-client/types"
tibchost "github.com/bianjieai/tibc-go/modules/tibc/core/24-host"
migratehtlc "github.com/nimrostafarian/gridfury/migrate/htlc"
migrateservice "github.com/nimrostafarian/gridfury/migrate/service"
migratetibc "github.com/nimrostafarian/gridfury/migrate/tibc"
"github.com/nimrostafarian/gridfury/modules/guardian"
guardiantypes "github.com/nimrostafarian/gridfury/modules/guardian/types"
"github.com/nimrostafarian/gridfury/modules/mint"
minttypes "github.com/nimrostafarian/gridfury/modules/mint/types"
"github.com/nimrostafarian/gridfury/types"
)
// RegisterUpgradePlan register a handler of upgrade plan
func (app *FuryApp) RegisterUpgradePlan(cfg module.Configurator) {
app.RegisterUpgradeHandler(
"v1.1", &store.StoreUpgrades{},
func(ctx sdk.Context, plan sdkupgrade.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// migrate htlc
if err := migratehtlc.Migrate(ctx, app.appCodec, app.HTLCKeeper, app.BankKeeper, app.keys[htlctypes.StoreKey]); err != nil {
panic(err)
}
// migrate service
if err := migrateservice.Migrate(ctx, app.ServiceKeeper, app.BankKeeper); err != nil {
panic(err)
}
return fromVM, nil
},
)
app.RegisterUpgradeHandler(
"v1.2", &store.StoreUpgrades{
Added: []string{farmtypes.StoreKey, feegrant.StoreKey, tibchost.StoreKey, tibcnfttypes.StoreKey},
},
func(ctx sdk.Context, plan sdkupgrade.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// init farm params
amount := sdkmath.NewIntWithDecimal(1000, int(types.NativeToken.Scale))
farmtypes.SetDefaultGenesisState(farmtypes.GenesisState{
Params: farmtypes.Params{
PoolCreationFee: sdk.NewCoin(types.NativeToken.MinUnit, amount),
MaxRewardCategories: 2,
}},
)
tibcclienttypes.SetDefaultGenesisState(tibcclienttypes.GenesisState{
NativeChainName: "gridfury-mainnet",
})
if err := migratetibc.CreateClient(ctx,
app.appCodec,
"v1.2",
app.TIBCKeeper.ClientKeeper,
); err != nil {
return nil, err
}
fromVM[authtypes.ModuleName] = 1
fromVM[banktypes.ModuleName] = 1
fromVM[stakingtypes.ModuleName] = 1
fromVM[govtypes.ModuleName] = 1
fromVM[distrtypes.ModuleName] = 1
fromVM[slashingtypes.ModuleName] = 1
fromVM[coinswaptypes.ModuleName] = 1
fromVM[ibchost.ModuleName] = 1
fromVM[capabilitytypes.ModuleName] = capability.AppModule{}.ConsensusVersion()
fromVM[genutiltypes.ModuleName] = genutil.AppModule{}.ConsensusVersion()
fromVM[minttypes.ModuleName] = mint.AppModule{}.ConsensusVersion()
fromVM[paramstypes.ModuleName] = params.AppModule{}.ConsensusVersion()
fromVM[crisistypes.ModuleName] = crisis.AppModule{}.ConsensusVersion()
fromVM[upgradetypes.ModuleName] = crisis.AppModule{}.ConsensusVersion()
fromVM[evidencetypes.ModuleName] = evidence.AppModule{}.ConsensusVersion()
fromVM[feegrant.ModuleName] = feegrantmodule.AppModule{}.ConsensusVersion()
fromVM[guardiantypes.ModuleName] = guardian.AppModule{}.ConsensusVersion()
fromVM[tokentypes.ModuleName] = token.AppModule{}.ConsensusVersion()
fromVM[recordtypes.ModuleName] = record.AppModule{}.ConsensusVersion()
fromVM[nfttypes.ModuleName] = nftmodule.AppModule{}.ConsensusVersion()
fromVM[htlctypes.ModuleName] = htlc.AppModule{}.ConsensusVersion()
fromVM[servicetypes.ModuleName] = service.AppModule{}.ConsensusVersion()
fromVM[oracletypes.ModuleName] = oracle.AppModule{}.ConsensusVersion()
fromVM[randomtypes.ModuleName] = random.AppModule{}.ConsensusVersion()
return app.mm.RunMigrations(ctx, cfg, fromVM)
},
)
app.RegisterUpgradeHandler("v1.3",
&store.StoreUpgrades{
Added: []string{tibcmttypes.StoreKey, mttypes.StoreKey},
},
func(ctx sdk.Context, plan sdkupgrade.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
if err := migratetibc.CreateClient(ctx,
app.appCodec,
"v1.3",
app.TIBCKeeper.ClientKeeper,
); err != nil {
return nil, err
}
return app.mm.RunMigrations(ctx, cfg, fromVM)
},
)
app.RegisterUpgradeHandler("v1.4",
&store.StoreUpgrades{
Added: []string{authzkeeper.StoreKey},
},
func(ctx sdk.Context, plan sdkupgrade.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// version upgrade:
// nft : 1 -> 2
// auth: 2 -> 3
// bank: 2 -> 3
// coinswap 3 -> 4
// feegrant 1 -> 2
// gov 2 -> 3
// staking 2 -> 3
// upgrade 2 -> 3
// added module:
// authz
// ibc application:
// 27-interchain-accounts
icaModule := app.mm.Modules[icatypes.ModuleName].(ica.AppModule)
fromVM[icatypes.ModuleName] = icaModule.ConsensusVersion()
// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{}
// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: types.ICAMsgs,
}
ctx.Logger().Info("start to init interchainaccount module...")
// initialize ICS27 module
icaModule.InitModule(ctx, controllerParams, hostParams)
ctx.Logger().Info("start to run module migrations...")
return app.mm.RunMigrations(ctx, cfg, fromVM)
},
)
}