-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
569 lines (498 loc) · 20.7 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
package app
import (
"fmt"
"io"
"os"
evmtypes "github.com/fastock/fastock-chain/x/evm/types"
"github.com/fastock/fastock-chain/app/ante"
blockchaincodec "github.com/fastock/fastock-chain/app/codec"
blockchain "github.com/fastock/fastock-chain/app/types"
"github.com/fastock/fastock-chain/x/ammswap"
"github.com/fastock/fastock-chain/x/backend"
commonversion "github.com/fastock/fastock-chain/x/common/version"
"github.com/fastock/fastock-chain/x/debug"
"github.com/fastock/fastock-chain/x/dex"
dexclient "github.com/fastock/fastock-chain/x/dex/client"
distr "github.com/fastock/fastock-chain/x/distribution"
"github.com/fastock/fastock-chain/x/evidence"
"github.com/fastock/fastock-chain/x/evm"
"github.com/fastock/fastock-chain/x/farm"
farmclient "github.com/fastock/fastock-chain/x/farm/client"
"github.com/fastock/fastock-chain/x/genutil"
"github.com/fastock/fastock-chain/x/gov"
"github.com/fastock/fastock-chain/x/gov/keeper"
"github.com/fastock/fastock-chain/x/order"
"github.com/fastock/fastock-chain/x/params"
paramsclient "github.com/fastock/fastock-chain/x/params/client"
"github.com/fastock/fastock-chain/x/slashing"
"github.com/fastock/fastock-chain/x/staking"
"github.com/fastock/fastock-chain/x/stream"
"github.com/fastock/fastock-chain/x/token"
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/simapp"
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"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/cosmos/cosmos-sdk/x/upgrade"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
)
func init() {
// set the address prefixes
config := sdk.GetConfig()
blockchain.SetBech32Prefixes(config)
blockchain.SetBip44CoinType(config)
}
const appName = "Blockchain"
var (
// DefaultCLIHome sets the default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.fastock-chain-cli")
// DefaultNodeHome sets the folder where the applcation data and configuration will be stored
DefaultNodeHome = os.ExpandEnv("$HOME/.fastock-chain-daemon")
// 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{},
supply.AppModuleBasic{},
genutil.AppModuleBasic{},
bank.AppModuleBasic{},
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distr.ProposalHandler,
dexclient.DelistProposalHandler, farmclient.ManageWhiteListProposalHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
evidence.AppModuleBasic{},
upgrade.AppModuleBasic{},
evm.AppModuleBasic{},
token.AppModuleBasic{},
dex.AppModuleBasic{},
order.AppModuleBasic{},
backend.AppModuleBasic{},
stream.AppModuleBasic{},
debug.AppModuleBasic{},
ammswap.AppModuleBasic{},
farm.AppModuleBasic{},
)
// module account permissions
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
mint.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: nil,
token.ModuleName: {supply.Minter, supply.Burner},
dex.ModuleName: nil,
order.ModuleName: nil,
backend.ModuleName: nil,
ammswap.ModuleName: {supply.Minter, supply.Burner},
farm.ModuleName: nil,
farm.YieldFarmingAccount: nil,
farm.MintFarmingAccount: {supply.Burner},
}
// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
distr.ModuleName: true,
}
)
var _ simapp.App = (*BlockchainApp)(nil)
// BlockchainApp implements an extended ABCI application. It is an application
// that may process transactions through Ethereum's EVM running atop of
// Tendermint consensus.
type BlockchainApp struct {
*bam.BaseApp
cdc *codec.Codec
invCheckPeriod uint
// keys to access the substores
keys map[string]*sdk.KVStoreKey
tkeys map[string]*sdk.TransientStoreKey
// subspaces
subspaces map[string]params.Subspace
// keepers
AccountKeeper auth.AccountKeeper
BankKeeper bank.Keeper
SupplyKeeper supply.Keeper
StakingKeeper staking.Keeper
SlashingKeeper slashing.Keeper
MintKeeper mint.Keeper
DistrKeeper distr.Keeper
GovKeeper gov.Keeper
CrisisKeeper crisis.Keeper
UpgradeKeeper upgrade.Keeper
ParamsKeeper params.Keeper
EvidenceKeeper evidence.Keeper
EvmKeeper *evm.Keeper
TokenKeeper token.Keeper
DexKeeper dex.Keeper
OrderKeeper order.Keeper
SwapKeeper ammswap.Keeper
FarmKeeper farm.Keeper
BackendKeeper backend.Keeper
StreamKeeper stream.Keeper
// the module manager
mm *module.Manager
// simulation manager
sm *module.SimulationManager
}
// NewBlockchainApp returns a reference to a new initialized Blockchain application.
func NewBlockchainApp(
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
invCheckPeriod uint,
baseAppOptions ...func(*bam.BaseApp),
) *BlockchainApp {
// get config
appConfig, err := config.ParseConfig()
if err != nil {
logger.Error(fmt.Sprintf("the config of Blockchain was parsed error : %s", err.Error()))
panic(err)
}
cdc := blockchaincodec.MakeCodec(ModuleBasics)
// NOTE we use custom Blockchain transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
bApp := bam.NewBaseApp(appName, logger, db, evm.TxDecoder(cdc), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetAppVersion(version.Version)
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
gov.StoreKey, params.StoreKey, upgrade.StoreKey, evidence.StoreKey,
evm.StoreKey, token.StoreKey, token.KeyLock, dex.StoreKey, dex.TokenPairStoreKey,
order.OrderStoreKey, ammswap.StoreKey, farm.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)
app := &BlockchainApp{
BaseApp: bApp,
cdc: cdc,
invCheckPeriod: invCheckPeriod,
keys: keys,
tkeys: tkeys,
subspaces: make(map[string]params.Subspace),
}
// init params keeper and subspaces
app.ParamsKeeper = params.NewKeeper(cdc, keys[params.StoreKey], tkeys[params.TStoreKey])
app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace)
app.subspaces[bank.ModuleName] = app.ParamsKeeper.Subspace(bank.DefaultParamspace)
app.subspaces[staking.ModuleName] = app.ParamsKeeper.Subspace(staking.DefaultParamspace)
app.subspaces[mint.ModuleName] = app.ParamsKeeper.Subspace(mint.DefaultParamspace)
app.subspaces[distr.ModuleName] = app.ParamsKeeper.Subspace(distr.DefaultParamspace)
app.subspaces[slashing.ModuleName] = app.ParamsKeeper.Subspace(slashing.DefaultParamspace)
app.subspaces[gov.ModuleName] = app.ParamsKeeper.Subspace(gov.DefaultParamspace)
app.subspaces[crisis.ModuleName] = app.ParamsKeeper.Subspace(crisis.DefaultParamspace)
app.subspaces[evidence.ModuleName] = app.ParamsKeeper.Subspace(evidence.DefaultParamspace)
app.subspaces[evm.ModuleName] = app.ParamsKeeper.Subspace(evm.DefaultParamspace)
app.subspaces[token.ModuleName] = app.ParamsKeeper.Subspace(token.DefaultParamspace)
app.subspaces[dex.ModuleName] = app.ParamsKeeper.Subspace(dex.DefaultParamspace)
app.subspaces[order.ModuleName] = app.ParamsKeeper.Subspace(order.DefaultParamspace)
app.subspaces[ammswap.ModuleName] = app.ParamsKeeper.Subspace(ammswap.DefaultParamspace)
app.subspaces[farm.ModuleName] = app.ParamsKeeper.Subspace(farm.DefaultParamspace)
// use custom Blockchain account for contracts
app.AccountKeeper = auth.NewAccountKeeper(
cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], blockchain.ProtoAccount,
)
app.BankKeeper = bank.NewBaseKeeper(
app.AccountKeeper, app.subspaces[bank.ModuleName], app.BlacklistedAccAddrs(),
)
app.ParamsKeeper.SetBankKeeper(app.BankKeeper)
app.SupplyKeeper = supply.NewKeeper(
cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
cdc, keys[staking.StoreKey], app.SupplyKeeper, app.subspaces[staking.ModuleName],
)
app.ParamsKeeper.SetStakingKeeper(stakingKeeper)
app.MintKeeper = mint.NewKeeper(
cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName, farm.MintFarmingAccount,
)
app.DistrKeeper = distr.NewKeeper(
cdc, keys[distr.StoreKey], app.subspaces[distr.ModuleName], &stakingKeeper,
app.SupplyKeeper, auth.FeeCollectorName, app.ModuleAccountAddrs(),
)
app.SlashingKeeper = slashing.NewKeeper(
cdc, keys[slashing.StoreKey], &stakingKeeper, app.subspaces[slashing.ModuleName],
)
app.CrisisKeeper = crisis.NewKeeper(
app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName,
)
app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc)
app.EvmKeeper = evm.NewKeeper(
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper, app.SupplyKeeper, app.BankKeeper)
app.TokenKeeper = token.NewKeeper(app.BankKeeper, app.subspaces[token.ModuleName], auth.FeeCollectorName, app.SupplyKeeper,
keys[token.StoreKey], keys[token.KeyLock],
app.cdc, appConfig.BackendConfig.EnableBackend)
app.DexKeeper = dex.NewKeeper(auth.FeeCollectorName, app.SupplyKeeper, app.subspaces[dex.ModuleName], app.TokenKeeper, &stakingKeeper,
app.BankKeeper, app.keys[dex.StoreKey], app.keys[dex.TokenPairStoreKey], app.cdc)
app.OrderKeeper = order.NewKeeper(
app.TokenKeeper, app.SupplyKeeper, app.DexKeeper, app.subspaces[order.ModuleName], auth.FeeCollectorName,
app.keys[order.OrderStoreKey], app.cdc, appConfig.BackendConfig.EnableBackend, orderMetrics,
)
app.SwapKeeper = ammswap.NewKeeper(app.SupplyKeeper, app.TokenKeeper, app.cdc, app.keys[ammswap.StoreKey], app.subspaces[ammswap.ModuleName])
app.FarmKeeper = farm.NewKeeper(auth.FeeCollectorName, app.SupplyKeeper, app.TokenKeeper, app.SwapKeeper, app.subspaces[farm.StoreKey],
app.keys[farm.StoreKey], app.cdc)
app.StreamKeeper = stream.NewKeeper(app.OrderKeeper, app.TokenKeeper, &app.DexKeeper, &app.AccountKeeper, &app.SwapKeeper,
&app.FarmKeeper, app.cdc, logger, appConfig, streamMetrics)
app.BackendKeeper = backend.NewKeeper(app.OrderKeeper, app.TokenKeeper, &app.DexKeeper, &app.SwapKeeper, &app.FarmKeeper,
app.MintKeeper, app.StreamKeeper.GetMarketKeeper(), app.cdc, logger, appConfig.BackendConfig)
// create evidence keeper with router
evidenceKeeper := evidence.NewKeeper(
cdc, keys[evidence.StoreKey], app.subspaces[evidence.ModuleName], &app.StakingKeeper, app.SlashingKeeper,
)
evidenceRouter := evidence.NewRouter()
evidenceKeeper.SetRouter(evidenceRouter)
app.EvidenceKeeper = *evidenceKeeper
// register the proposal types
// 3.register the proposal types
govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(&app.ParamsKeeper)).
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(dex.RouterKey, dex.NewProposalHandler(&app.DexKeeper)).
AddRoute(farm.RouterKey, farm.NewManageWhiteListProposalHandler(&app.FarmKeeper))
govProposalHandlerRouter := keeper.NewProposalHandlerRouter()
govProposalHandlerRouter.AddRoute(params.RouterKey, &app.ParamsKeeper).
AddRoute(dex.RouterKey, &app.DexKeeper).
AddRoute(farm.RouterKey, &app.FarmKeeper)
app.GovKeeper = gov.NewKeeper(
app.cdc, app.keys[gov.StoreKey], app.ParamsKeeper, app.subspaces[gov.DefaultParamspace],
app.SupplyKeeper, &stakingKeeper, gov.DefaultParamspace, govRouter,
app.BankKeeper, govProposalHandlerRouter, auth.FeeCollectorName,
)
app.ParamsKeeper.SetGovKeeper(app.GovKeeper)
app.DexKeeper.SetGovKeeper(app.GovKeeper)
app.FarmKeeper.SetGovKeeper(app.GovKeeper)
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
staking.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)
// 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),
auth.NewAppModule(app.AccountKeeper),
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
crisis.NewAppModule(&app.CrisisKeeper),
supply.NewAppModule(app.SupplyKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.StakingKeeper),
distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
token.NewAppModule(commonversion.ProtocolVersionV0, app.TokenKeeper, app.SupplyKeeper),
dex.NewAppModule(commonversion.ProtocolVersionV0, app.DexKeeper, app.SupplyKeeper),
order.NewAppModule(commonversion.ProtocolVersionV0, app.OrderKeeper, app.SupplyKeeper),
ammswap.NewAppModule(app.SwapKeeper),
farm.NewAppModule(app.FarmKeeper),
backend.NewAppModule(app.BackendKeeper),
stream.NewAppModule(app.StreamKeeper),
params.NewAppModule(app.ParamsKeeper),
)
// 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.
app.mm.SetOrderBeginBlockers(
stream.ModuleName,
order.ModuleName,
token.ModuleName,
dex.ModuleName,
mint.ModuleName,
distr.ModuleName,
slashing.ModuleName,
staking.ModuleName,
farm.ModuleName,
evidence.ModuleName,
evm.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisis.ModuleName,
gov.ModuleName,
dex.ModuleName,
order.ModuleName,
staking.ModuleName,
backend.ModuleName,
stream.ModuleName,
evm.ModuleName,
)
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
app.mm.SetOrderInitGenesis(
auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName,
token.ModuleName, dex.ModuleName, order.ModuleName, ammswap.ModuleName, farm.ModuleName,
evm.ModuleName, crisis.ModuleName, genutil.ModuleName, params.ModuleName, evidence.ModuleName,
)
app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
// 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(app.AccountKeeper),
bank.NewAppModule(app.BankKeeper, app.AccountKeeper),
supply.NewAppModule(app.SupplyKeeper, app.AccountKeeper),
gov.NewAppModule(app.GovKeeper, app.SupplyKeeper),
mint.NewAppModule(app.MintKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
distr.NewAppModule(app.DistrKeeper, app.SupplyKeeper),
slashing.NewAppModule(app.SlashingKeeper, app.AccountKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper), // NOTE: only used for simulation to generate randomized param change proposals
)
app.sm.RegisterStoreDecoders()
// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(ante.NewAnteHandler(app.AccountKeeper, app.EvmKeeper, app.SupplyKeeper, validateMsgHook(app.OrderKeeper)))
app.SetEndBlocker(app.EndBlocker)
if loadLatest {
err := app.LoadLatestVersion(app.keys[bam.MainStoreKey])
if err != nil {
tmos.Exit(err.Error())
}
}
return app
}
// Name returns the name of the App
func (app *BlockchainApp) Name() string { return app.BaseApp.Name() }
// BeginBlocker updates every begin block
func (app *BlockchainApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}
// EndBlocker updates every end block
func (app *BlockchainApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}
func (app *BlockchainApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
resp := app.BaseApp.DeliverTx(req)
if (app.BackendKeeper.Config.EnableBackend || app.StreamKeeper.AnalysisEnable()) && resp.IsOK() {
app.syncTx(req.Tx)
}
return resp
}
func (app *BlockchainApp) syncTx(txBytes []byte) {
if tx, err := auth.DefaultTxDecoder(app.Codec())(txBytes); err == nil {
if stdTx, ok := tx.(auth.StdTx); ok {
txHash := fmt.Sprintf("%X", tmhash.Sum(txBytes))
app.Logger().Debug(fmt.Sprintf("[Sync Tx(%s) to backend module]", txHash))
ctx := app.GetDeliverStateCtx()
app.BackendKeeper.SyncTx(ctx, &stdTx, txHash,
ctx.BlockHeader().Time.Unix())
app.StreamKeeper.SyncTx(ctx, &stdTx, txHash,
ctx.BlockHeader().Time.Unix())
}
}
}
// InitChainer updates at chain initialization
func (app *BlockchainApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState simapp.GenesisState
app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState)
return app.mm.InitGenesis(ctx, genesisState)
}
// LoadHeight loads state at a particular height
func (app *BlockchainApp) LoadHeight(height int64) error {
return app.LoadVersion(height, app.keys[bam.MainStoreKey])
}
// ModuleAccountAddrs returns all the app's module account addresses.
func (app *BlockchainApp) ModuleAccountAddrs() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range maccPerms {
modAccAddrs[supply.NewModuleAddress(acc).String()] = true
}
return modAccAddrs
}
// BlacklistedAccAddrs returns all the app's module account addresses black listed for receiving tokens.
func (app *BlockchainApp) BlacklistedAccAddrs() map[string]bool {
blacklistedAddrs := make(map[string]bool)
for acc := range maccPerms {
blacklistedAddrs[supply.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}
return blacklistedAddrs
}
// SimulationManager implements the SimulationApp interface
func (app *BlockchainApp) SimulationManager() *module.SimulationManager {
return app.sm
}
// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
func (app *BlockchainApp) GetKey(storeKey string) *sdk.KVStoreKey {
return app.keys[storeKey]
}
// Codec returns Blockchain's 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 *BlockchainApp) Codec() *codec.Codec {
return app.cdc
}
// GetSubspace returns a param subspace for a given module name.
//
// NOTE: This is solely to be used for testing purposes.
func (app *BlockchainApp) GetSubspace(moduleName string) params.Subspace {
return app.subspaces[moduleName]
}
// 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
}
func validateMsgHook(orderKeeper order.Keeper) ante.ValidateMsgHandler {
return func(newCtx sdk.Context, msgs []sdk.Msg) error {
wrongMsgErr := sdk.ErrUnknownRequest(
"It is not allowed that a transaction with more than one message contains order or evm message")
var err error
for _, msg := range msgs {
switch assertedMsg := msg.(type) {
case order.MsgNewOrders:
if len(msgs) > 1 {
return wrongMsgErr
}
_, err = order.ValidateMsgNewOrders(newCtx, orderKeeper, assertedMsg)
case order.MsgCancelOrders:
if len(msgs) > 1 {
return wrongMsgErr
}
err = order.ValidateMsgCancelOrders(newCtx, orderKeeper, assertedMsg)
case evmtypes.MsgEthereumTx:
if len(msgs) > 1 {
return wrongMsgErr
}
case evmtypes.MsgEthermint:
if len(msgs) > 1 {
return wrongMsgErr
}
}
if err != nil {
return err
}
}
return nil
}
}