-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathapp_config.go
423 lines (372 loc) · 14.2 KB
/
app_config.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
package app
import (
"os"
"path/filepath"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cast"
"github.com/cosmos/cosmos-sdk/x/consensus"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/evidence"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/capability"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/desmos-labs/desmos/v7/x/posts"
postskeeper "github.com/desmos-labs/desmos/v7/x/posts/keeper"
poststypes "github.com/desmos-labs/desmos/v7/x/posts/types"
"github.com/desmos-labs/desmos/v7/x/profiles"
profileskeeper "github.com/desmos-labs/desmos/v7/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v7/x/profiles/types"
"github.com/desmos-labs/desmos/v7/x/reactions"
reactionskeeper "github.com/desmos-labs/desmos/v7/x/reactions/keeper"
reactionstypes "github.com/desmos-labs/desmos/v7/x/reactions/types"
"github.com/desmos-labs/desmos/v7/x/relationships"
relationshipskeeper "github.com/desmos-labs/desmos/v7/x/relationships/keeper"
relationshipstypes "github.com/desmos-labs/desmos/v7/x/relationships/types"
"github.com/desmos-labs/desmos/v7/x/reports"
reportskeeper "github.com/desmos-labs/desmos/v7/x/reports/keeper"
reportstypes "github.com/desmos-labs/desmos/v7/x/reports/types"
"github.com/desmos-labs/desmos/v7/x/subspaces"
subspaceskeeper "github.com/desmos-labs/desmos/v7/x/subspaces/keeper"
subspacestypes "github.com/desmos-labs/desmos/v7/x/subspaces/types"
supplytypes "github.com/desmos-labs/desmos/v7/x/supply/types"
"github.com/desmos-labs/desmos/v7/x/tokenfactory"
tokenfactorytypes "github.com/desmos-labs/desmos/v7/x/tokenfactory/types"
"github.com/desmos-labs/desmos/v7/x/supply"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)
const (
appName = "Desmos"
Bech32MainPrefix = "desmos"
CoinType = 852
FullFundraiserPath = "44'/852'/0'/0/0"
)
// GetWasmOpts parses appOpts and add wasm opt to the given options array.
// if telemetry is enabled, the wasmVM cache metrics are activated.
func GetWasmOpts(
appOpts servertypes.AppOptions,
grpcQueryRouter *baseapp.GRPCQueryRouter,
cdc codec.Codec,
profilesKeeper *profileskeeper.Keeper,
subspacesKeeper *subspaceskeeper.Keeper,
relationshipsKeeper relationshipskeeper.Keeper,
postsKeeper *postskeeper.Keeper,
reportsKeeper reportskeeper.Keeper,
reactionsKeeper reactionskeeper.Keeper,
) []wasmkeeper.Option {
var wasmOpts []wasmkeeper.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}
customQueryPlugin := NewDesmosCustomQueryPlugin(
cdc,
grpcQueryRouter,
profilesKeeper,
subspacesKeeper,
relationshipsKeeper,
postsKeeper,
reportsKeeper,
reactionsKeeper,
)
customMessageEncoder := NewDesmosCustomMessageEncoder(cdc)
wasmOpts = append(wasmOpts, wasmkeeper.WithGasRegister(NewDesmosWasmGasRegister()))
wasmOpts = append(wasmOpts, wasmkeeper.WithQueryPlugins(&customQueryPlugin))
wasmOpts = append(wasmOpts, wasmkeeper.WithMessageEncoders(&customMessageEncoder))
return wasmOpts
}
var (
// DefaultNodeHome sets the folder where the application data and configuration will be stored
DefaultNodeHome string
// ModuleBasics is in charge of setting up basic module elements
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
},
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
wasm.AppModuleBasic{},
// IBC modules
ibc.AppModuleBasic{},
solomachine.AppModuleBasic{},
ibctm.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ibcfee.AppModuleBasic{},
ica.AppModuleBasic{},
// Custom modules
profiles.AppModuleBasic{},
relationships.AppModuleBasic{},
subspaces.AppModuleBasic{},
posts.AppModuleBasic{},
reports.AppModuleBasic{},
reactions.AppModuleBasic{},
supply.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
)
// Module account permissions
maccPerms = []*authmodulev1.ModuleAccountPermission{
{Account: authtypes.FeeCollectorName},
{Account: distrtypes.ModuleName},
{Account: minttypes.ModuleName, Permissions: []string{authtypes.Minter}},
{Account: stakingtypes.BondedPoolName, Permissions: []string{authtypes.Burner, authtypes.Staking}},
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, authtypes.Staking}},
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: ibctransfertypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
{Account: wasmtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: ibcfeetypes.ModuleName},
{Account: icatypes.ModuleName},
{Account: tokenfactorytypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
}
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
beginBlockerOrder = []string{
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
// IBC modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// Custom modules
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
tokenfactorytypes.ModuleName,
wasmtypes.ModuleName,
}
endBlockerOrder = []string{
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
// IBC modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// Custom modules
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
tokenfactorytypes.ModuleName,
wasmtypes.ModuleName,
}
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
// NOTE: wasm module should be at the end as it can call other module functionality direct or via message dispatching during
// genesis phase. For example bank transfer, auth account check, staking, ...
genesisModuleOrder = []string{
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
// IBC modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// Custom modules
subspacestypes.ModuleName,
profilestypes.ModuleName,
relationshipstypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
tokenfactorytypes.ModuleName,
// wasm module should be at the end of app modules
wasmtypes.ModuleName,
crisistypes.ModuleName,
}
// NOTE: The auth module must occur before everyone else. All other modules can be sorted
// alphabetically (default order)
// NOTE: The relationships module must occur before the profiles module, or all relationships will be deleted
migrationModuleOrder = []string{
authtypes.ModuleName,
authz.ModuleName,
banktypes.ModuleName,
capabilitytypes.ModuleName,
distrtypes.ModuleName,
evidencetypes.ModuleName,
feegrant.ModuleName,
genutiltypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
slashingtypes.ModuleName,
stakingtypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
// IBC modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,
// Custom modules
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
tokenfactorytypes.ModuleName,
wasmtypes.ModuleName,
crisistypes.ModuleName,
}
)
func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
DefaultNodeHome = filepath.Join(userHomeDir, ".desmos")
}
// SetupConfig sets up the given config as it should be for Desmos
func SetupConfig(config *sdk.Config) {
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32MainPrefix+sdk.PrefixPublic)
config.SetBech32PrefixForValidator(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator+sdk.PrefixPublic)
config.SetBech32PrefixForConsensusNode(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus+sdk.PrefixPublic)
// 852 is the international dialing code of Hong Kong
// Following the coin type registered at https://github.com/satoshilabs/slips/blob/master/slip-0044.md
config.SetCoinType(CoinType)
}
// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
// DesmosApp. It is useful for tests and clients who do not want to construct the
// full DesmosApp
func MakeCodecs() (codec.Codec, *codec.LegacyAmino) {
cfg := MakeEncodingConfig()
return cfg.Codec, cfg.Amino
}
// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for _, perms := range maccPerms {
dupMaccPerms[perms.Account] = perms.Permissions
}
return dupMaccPerms
}