-
Notifications
You must be signed in to change notification settings - Fork 127
/
app.go
783 lines (689 loc) · 23.5 KB
/
app.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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
package simapp
import (
"encoding/json"
"io"
"os"
"path/filepath"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/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/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"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"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
simappparams "cosmossdk.io/simapp/params"
tokentypes "github.com/irisnet/irismod/modules/token/types"
tokenv1 "github.com/irisnet/irismod/modules/token/types/v1"
"github.com/irisnet/irishub/v2/address"
"github.com/irisnet/irishub/v2/lite"
"github.com/irisnet/irishub/v2/modules/guardian"
guardiankeeper "github.com/irisnet/irishub/v2/modules/guardian/keeper"
guardiantypes "github.com/irisnet/irishub/v2/modules/guardian/types"
"github.com/irisnet/irishub/v2/modules/mint"
mintkeeper "github.com/irisnet/irishub/v2/modules/mint/keeper"
minttypes "github.com/irisnet/irishub/v2/modules/mint/types"
tibcmttransfer "github.com/bianjieai/tibc-go/modules/tibc/apps/mt_transfer"
tibcnfttransfer "github.com/bianjieai/tibc-go/modules/tibc/apps/nft_transfer"
)
const appName = "SimApp"
var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
// Denominations can be 3 ~ 128 characters long and support letters, followed by either
// a letter, a number, ('-'), or a separator ('/').
// overwite sdk reDnmString
reDnmString = `[a-zA-Z][a-zA-Z0-9/-]{2,127}`
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
params.AppModuleBasic{},
slashing.AppModuleBasic{},
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
crisis.AppModuleBasic{},
guardian.AppModuleBasic{},
mint.AppModuleBasic{},
)
// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
}
nativeToken tokenv1.Token
)
var (
_ runtime.AppI = (*SimApp)(nil)
_ servertypes.Application = (*SimApp)(nil)
)
// SimApp extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
type SimApp struct {
*baseapp.BaseApp
legacyAmino *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
configurator module.Configurator
txConfig client.TxConfig
invCheckPeriod uint
// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
memKeys map[string]*storetypes.MemoryStoreKey
// cosmos
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
DistrKeeper distrkeeper.Keeper
ParamsKeeper paramskeeper.Keeper
ConsensusParamsKeeper consensuskeeper.Keeper
GuardianKeeper guardiankeeper.Keeper
MintKeeper mintkeeper.Keeper
// the module manager
mm *module.Manager
// simulation manager
sm *module.SimulationManager
transferModule transfer.AppModule
nfttransferModule tibcnfttransfer.AppModule
mttransferModule tibcmttransfer.AppModule
}
func init() {
// set bech32 prefix
address.ConfigureBech32Prefix()
// set coin denom regexs
sdk.SetCoinDenomRegex(DefaultCoinDenomRegex)
nativeToken = tokenv1.Token{
Symbol: "iris",
Name: "Irishub staking token",
Scale: 6,
MinUnit: "uiris",
InitialSupply: 2000000000,
MaxSupply: 10000000000,
Mintable: true,
Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(),
}
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
DefaultNodeHome = filepath.Join(userHomeDir, ".iris")
owner, err := sdk.AccAddressFromBech32(nativeToken.Owner)
if err != nil {
panic(err)
}
tokenv1.SetNativeToken(
nativeToken.Symbol,
nativeToken.Name,
nativeToken.MinUnit,
nativeToken.Scale,
nativeToken.InitialSupply,
nativeToken.MaxSupply,
nativeToken.Mintable,
owner,
)
}
// DefaultCoinDenomRegex returns the default regex string
func DefaultCoinDenomRegex() string {
return reDnmString
}
// NewSimApp returns a reference to an initialized IrisApp.
func NewSimApp(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *SimApp {
// TODO: Remove cdc in favor of appCodec once all modules are migrated.
appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
bApp := baseapp.NewBaseApp(
appName,
logger,
db,
encodingConfig.TxConfig.TxDecoder(),
baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
keys := sdk.NewKVStoreKeys(
authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
crisistypes.StoreKey,
consensustypes.StoreKey,
paramstypes.StoreKey,
capabilitytypes.StoreKey,
guardiantypes.StoreKey,
minttypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil {
tmos.Exit(err.Error())
}
app := &SimApp{
BaseApp: bApp,
legacyAmino: legacyAmino,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
txConfig: encodingConfig.TxConfig,
}
app.ParamsKeeper = initParamsKeeper(
appCodec,
legacyAmino,
keys[paramstypes.StoreKey],
tkeys[paramstypes.TStoreKey],
)
app.ConsensusParamsKeeper = consensuskeeper.NewKeeper(
appCodec,
keys[consensustypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// set the BaseApp's parameter store
bApp.SetParamStore(&app.ConsensusParamsKeeper)
// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey],
)
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
authtypes.ProtoBaseAccount,
maccPerms,
address.Bech32PrefixAccAddr,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
app.BlockedModuleAccountAddrs(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
keys[minttypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.DistrKeeper = distrkeeper.NewKeeper(
appCodec,
keys[distrtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
keys[slashingtypes.StoreKey],
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
appCodec,
keys[crisistypes.StoreKey],
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)
app.GuardianKeeper = guardiankeeper.NewKeeper(
appCodec,
keys[guardiantypes.StoreKey],
)
/**** Module Options ****/
var skipGenesisInvariants = false
opt := appOpts.Get(crisis.FlagSkipGenesisInvariants)
if opt, ok := opt.(bool); ok {
skipGenesisInvariants = opt
}
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
),
auth.NewAppModule(
appCodec,
app.AccountKeeper,
authsims.RandomGenesisAccounts,
app.GetSubspace(authtypes.ModuleName),
),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(
appCodec,
app.BankKeeper,
app.AccountKeeper,
app.GetSubspace(banktypes.ModuleName),
),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(
app.CrisisKeeper,
skipGenesisInvariants,
app.GetSubspace(crisistypes.ModuleName),
),
mint.NewAppModule(appCodec, app.MintKeeper, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(
appCodec,
app.SlashingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(slashingtypes.ModuleName),
),
distr.NewAppModule(
appCodec,
app.DistrKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(distrtypes.ModuleName),
),
staking.NewAppModule(
appCodec,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
params.NewAppModule(app.ParamsKeeper),
guardian.NewAppModule(appCodec, app.GuardianKeeper),
)
// 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
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
minttypes.ModuleName,
guardiantypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
//sdk module
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
//self module
guardiantypes.ModuleName,
minttypes.ModuleName,
)
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// 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.
app.mm.SetOrderInitGenesis(
//sdk module
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensustypes.ModuleName,
//self module
guardiantypes.ModuleName,
minttypes.ModuleName,
)
cfg := module.NewConfigurator(appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.mm.RegisterInvariants(app.CrisisKeeper)
app.mm.RegisterServices(cfg)
// create the simulation manager and define the order of the modules for deterministic simulations
//
// NOTE: this is not required apps that don't use the simulator for fuzz testing
// transactions
app.sm = module.NewSimulationManager(
auth.NewAppModule(
appCodec,
app.AccountKeeper,
authsims.RandomGenesisAccounts,
app.GetSubspace(authtypes.ModuleName),
),
bank.NewAppModule(
appCodec,
app.BankKeeper,
app.AccountKeeper,
app.GetSubspace(banktypes.ModuleName),
),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
mint.NewAppModule(appCodec, app.MintKeeper, app.GetSubspace(minttypes.ModuleName)),
staking.NewAppModule(
appCodec,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
),
distr.NewAppModule(
appCodec,
app.DistrKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(distrtypes.ModuleName),
),
slashing.NewAppModule(
appCodec,
app.SlashingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.GetSubspace(slashingtypes.ModuleName),
),
params.NewAppModule(app.ParamsKeeper),
guardian.NewAppModule(appCodec, app.GuardianKeeper),
)
app.sm.RegisterStoreDecoders()
// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
app.MountMemoryStores(memKeys)
//app.SetAnteHandler(anteHandler)
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}
// Initialize and seal the capability keeper so all persistent capabilities
// are loaded in-memory and prevent any further modules from creating scoped
// sub-keepers.
// This must be done during creation of baseapp rather than in InitChain so
// that in-memory capabilities get regenerated on app restart.
// Note that since this reads from the store, we can only perform it when
// `loadLatest` is set to true.
app.CapabilityKeeper.Seal()
}
return app
}
// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
// irisapp. It is useful for tests and clients who do not want to construct the
// full irisapp
func MakeCodecs() (codec.Codec, *codec.LegacyAmino) {
config := MakeTestEncodingConfig()
return config.Codec, config.Amino
}
// Name returns the name of the App
func (app *SimApp) Name() string { return app.BaseApp.Name() }
// BeginBlocker application updates every begin block
func (app *SimApp) BeginBlocker(
ctx sdk.Context,
req abci.RequestBeginBlock,
) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}
// EndBlocker application updates every end block
func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}
// InitChainer application update at chain initialization
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}
// LoadHeight loads a particular height
func (app *SimApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}
// ModuleAccountAddrs returns all the app's module account addresses.
func (app *SimApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}
return modAccAddrs
}
// BlockedModuleAccountAddrs returns all the app's blocked module account
// addresses.
func (app *SimApp) BlockedModuleAccountAddrs() map[string]bool {
modAccAddrs := app.ModuleAccountAddrs()
// remove module accounts that are ALLOWED to received funds
//
// TODO: Blocked on updating to v0.46.x
// delete(modAccAddrs, authtypes.NewModuleAddress(grouptypes.ModuleName).String())
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())
return modAccAddrs
}
// LegacyAmino returns SimApp's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *SimApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}
// TxConfig returns SimApp's TxConfig
func (app *SimApp) TxConfig() client.TxConfig {
return app.txConfig
}
// DefaultGenesis returns a default genesis from the registered AppModuleBasic's.
func (a *SimApp) DefaultGenesis() map[string]json.RawMessage {
return ModuleBasics.DefaultGenesis(a.AppCodec())
}
// AppCodec returns IrisApp's app codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *SimApp) AppCodec() codec.Codec {
return app.appCodec
}
// InterfaceRegistry returns IrisApp's InterfaceRegistry
func (app *SimApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}
// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey {
return app.keys[storeKey]
}
// GetTKey returns the TransientStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *SimApp) GetTKey(storeKey string) *storetypes.TransientStoreKey {
return app.tkeys[storeKey]
}
// GetMemKey returns the MemStoreKey for the provided mem key.
//
// NOTE: This is solely used for testing purposes.
func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
return app.memKeys[storeKey]
}
// GetSubspace returns a param subspace for a given module name.
//
// NOTE: This is solely to be used for testing purposes.
func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}
// SimulationManager implements the SimulationApp interface
func (app *SimApp) SimulationManager() *module.SimulationManager {
return app.sm
}
// RegisterAPIRoutes registers all application module routes with the provided API server.
func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
clientCtx := apiSvr.ClientCtx
// Register new tx routes from grpc-gateway.
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register new tendermint queries routes from grpc-gateway.
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// Register grpc-gateway routes for all modules.
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
lite.RegisterSwaggerAPI(clientCtx, apiSvr.Router)
}
}
// RegisterTxService implements the Application.RegisterTxService method.
func (app *SimApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(
app.BaseApp.GRPCQueryRouter(),
clientCtx,
app.BaseApp.Simulate,
app.interfaceRegistry,
)
}
// RegisterTendermintService implements the Application.RegisterTendermintService method.
func (app *SimApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.interfaceRegistry,
app.Query,
)
}
func (app *SimApp) RegisterNodeService(clientCtx client.Context) {
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
}
// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}
return dupMaccPerms
}
// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(
appCodec codec.BinaryCodec,
legacyAmino *codec.LegacyAmino,
key, tkey storetypes.StoreKey,
) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
paramsKeeper.Subspace(authtypes.ModuleName)
paramsKeeper.Subspace(banktypes.ModuleName)
paramsKeeper.Subspace(stakingtypes.ModuleName)
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(crisistypes.ModuleName)
return paramsKeeper
}