1
1
package app
2
2
3
3
import (
4
+ "encoding/json"
4
5
"io"
5
- "net/http"
6
6
"os"
7
7
"path/filepath"
8
8
9
+ autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
10
+ reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
11
+ dbm "github.com/cometbft/cometbft-db"
12
+ abci "github.com/cometbft/cometbft/abci/types"
13
+ "github.com/cometbft/cometbft/libs/log"
14
+ tmos "github.com/cometbft/cometbft/libs/os"
9
15
"github.com/cosmos/cosmos-sdk/baseapp"
10
16
"github.com/cosmos/cosmos-sdk/client"
17
+ nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
11
18
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
12
- "github.com/cosmos/cosmos-sdk/client/rpc"
13
19
"github.com/cosmos/cosmos-sdk/codec"
14
20
"github.com/cosmos/cosmos-sdk/codec/types"
21
+ "github.com/cosmos/cosmos-sdk/runtime"
22
+ runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
23
+ "github.com/cosmos/cosmos-sdk/server"
15
24
"github.com/cosmos/cosmos-sdk/server/api"
16
25
"github.com/cosmos/cosmos-sdk/server/config"
17
26
servertypes "github.com/cosmos/cosmos-sdk/server/types"
27
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
18
28
sdk "github.com/cosmos/cosmos-sdk/types"
19
29
"github.com/cosmos/cosmos-sdk/types/module"
20
30
"github.com/cosmos/cosmos-sdk/version"
21
- authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
22
31
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
32
+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
33
+ consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
23
34
"github.com/cosmos/cosmos-sdk/x/params"
24
35
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
25
36
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
26
37
"github.com/cosmos/cosmos-sdk/x/upgrade"
27
38
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
28
39
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
29
- "github.com/tendermint/spm/cosmoscmd"
30
- "github.com/tendermint/spm/openapiconsole"
31
- abci "github.com/tendermint/tendermint/abci/types"
32
- tmjson "github.com/tendermint/tendermint/libs/json"
33
- "github.com/tendermint/tendermint/libs/log"
34
- tmos "github.com/tendermint/tendermint/libs/os"
35
- dbm "github.com/tendermint/tm-db"
36
- "github.com/zigbee-alliance/distributed-compliance-ledger/docs"
40
+
41
+ appparams "github.com/zigbee-alliance/distributed-compliance-ledger/app/params"
37
42
dclpkitypes "github.com/zigbee-alliance/distributed-compliance-ledger/types/pki"
38
43
compliancemodule "github.com/zigbee-alliance/distributed-compliance-ledger/x/compliance"
39
44
compliancemodulekeeper "github.com/zigbee-alliance/distributed-compliance-ledger/x/compliance/keeper"
@@ -142,7 +147,7 @@ var (
142
147
)
143
148
144
149
var (
145
- _ cosmoscmd. CosmosApp = (* App )(nil )
150
+ _ runtime. AppI = (* App )(nil )
146
151
_ servertypes.Application = (* App )(nil )
147
152
)
148
153
@@ -164,13 +169,14 @@ type App struct {
164
169
cdc * codec.LegacyAmino
165
170
appCodec codec.Codec
166
171
interfaceRegistry types.InterfaceRegistry
172
+ txConfig client.TxConfig
167
173
168
174
invCheckPeriod uint
169
175
170
176
// keys to access the substores
171
- keys map [string ]* sdk .KVStoreKey
172
- tkeys map [string ]* sdk .TransientStoreKey
173
- memKeys map [string ]* sdk .MemoryStoreKey
177
+ keys map [string ]* storetypes .KVStoreKey
178
+ tkeys map [string ]* storetypes .TransientStoreKey
179
+ memKeys map [string ]* storetypes .MemoryStoreKey
174
180
175
181
// keepers
176
182
/*
@@ -184,7 +190,7 @@ type App struct {
184
190
GovKeeper govkeeper.Keeper
185
191
CrisisKeeper crisiskeeper.Keeper
186
192
*/
187
- UpgradeKeeper upgradekeeper.Keeper
193
+ UpgradeKeeper * upgradekeeper.Keeper
188
194
ParamsKeeper paramskeeper.Keeper
189
195
/*
190
196
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
@@ -212,10 +218,24 @@ type App struct {
212
218
ModelKeeper modelmodulekeeper.Keeper
213
219
214
220
ComplianceKeeper compliancemodulekeeper.Keeper
221
+
222
+ ConsensusParamsKeeper consensusparamkeeper.Keeper
215
223
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
216
224
217
225
// the module manager
218
226
mm * module.Manager
227
+
228
+ // sm is the simulation manager
229
+ sm * module.SimulationManager
230
+ configurator module.Configurator
231
+ }
232
+
233
+ func (app * App ) RegisterNodeService (clientCtx client.Context ) {
234
+ nodeservice .RegisterNodeService (clientCtx , app .GRPCQueryRouter ())
235
+ }
236
+
237
+ func (app * App ) SimulationManager () * module.SimulationManager {
238
+ return app .sm
219
239
}
220
240
221
241
// New returns a reference to an initialized Gaia.
@@ -227,18 +247,20 @@ func New(
227
247
skipUpgradeHeights map [int64 ]bool ,
228
248
homePath string ,
229
249
invCheckPeriod uint ,
230
- encodingConfig cosmoscmd .EncodingConfig ,
250
+ encodingConfig appparams .EncodingConfig ,
231
251
appOpts servertypes.AppOptions ,
232
252
baseAppOptions ... func (* baseapp.BaseApp ),
233
- ) cosmoscmd. App {
234
- appCodec := encodingConfig .Marshaler
253
+ ) * App {
254
+ appCodec := encodingConfig .Codec
235
255
cdc := encodingConfig .Amino
236
256
interfaceRegistry := encodingConfig .InterfaceRegistry
257
+ txConfig := encodingConfig .TxConfig
237
258
238
259
bApp := baseapp .NewBaseApp (Name , logger , db , encodingConfig .TxConfig .TxDecoder (), baseAppOptions ... )
239
260
bApp .SetCommitMultiStoreTracer (traceStore )
240
261
bApp .SetVersion (version .Version )
241
262
bApp .SetInterfaceRegistry (interfaceRegistry )
263
+ bApp .SetTxEncoder (txConfig .TxEncoder ())
242
264
243
265
keys := sdk .NewKVStoreKeys (
244
266
paramstypes .StoreKey ,
@@ -267,6 +289,7 @@ func New(
267
289
cdc : cdc ,
268
290
appCodec : appCodec ,
269
291
interfaceRegistry : interfaceRegistry ,
292
+ txConfig : txConfig ,
270
293
invCheckPeriod : invCheckPeriod ,
271
294
keys : keys ,
272
295
tkeys : tkeys ,
@@ -276,8 +299,8 @@ func New(
276
299
app .ParamsKeeper = initParamsKeeper (appCodec , cdc , keys [paramstypes .StoreKey ], tkeys [paramstypes .TStoreKey ])
277
300
278
301
// set the BaseApp's parameter store
279
- bApp . SetParamStore ( app .ParamsKeeper . Subspace ( baseapp . Paramspace ). WithKeyTable ( paramskeeper . ConsensusParamsKeyTable () ))
280
- // add capability keeper and ScopeToModule for ibc module
302
+ app .ConsensusParamsKeeper = consensusparamkeeper . NewKeeper ( appCodec , keys [ upgradetypes . StoreKey ], authtypes . NewModuleAddress ( authtypes . ModuleName ). String ( ))
303
+ bApp . SetParamStore ( & app . ConsensusParamsKeeper ) // add capability keeper and ScopeToModule for ibc module
281
304
// app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
282
305
283
306
/*
@@ -315,7 +338,7 @@ func New(
315
338
316
339
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
317
340
*/
318
- app .UpgradeKeeper = upgradekeeper .NewKeeper (skipUpgradeHeights , keys [upgradetypes .StoreKey ], appCodec , homePath , app .BaseApp )
341
+ app .UpgradeKeeper = upgradekeeper .NewKeeper (skipUpgradeHeights , keys [upgradetypes .StoreKey ], appCodec , homePath , app .BaseApp , authtypes . NewModuleAddress ( upgradetypes . ModuleName ). String () )
319
342
/*
320
343
// register the staking hooks
321
344
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
@@ -371,7 +394,7 @@ func New(
371
394
keys [dclauthmoduletypes .MemStoreKey ],
372
395
)
373
396
374
- dclauthModule := dclauthmodule .NewAppModule (appCodec , app .DclauthKeeper , app . BaseauthKeeper )
397
+ dclauthModule := dclauthmodule .NewAppModule (appCodec , app .DclauthKeeper )
375
398
376
399
app .ValidatorKeeper = * validatormodulekeeper .NewKeeper (
377
400
appCodec ,
@@ -550,10 +573,23 @@ func New(
550
573
)
551
574
552
575
// app.mm.RegisterInvariants(&app.CrisisKeeper)
553
- app .mm .RegisterRoutes (app .Router (), app .QueryRouter (), encodingConfig .Amino )
576
+ //app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
577
+
578
+ app .configurator = module .NewConfigurator (app .appCodec , app .MsgServiceRouter (), app .GRPCQueryRouter ())
579
+ app .mm .RegisterServices (app .configurator )
580
+
581
+ autocliv1 .RegisterQueryServer (app .GRPCQueryRouter (), runtimeservices .NewAutoCLIQueryService (app .mm .Modules ))
582
+ reflectionSvc , err := runtimeservices .NewReflectionService ()
583
+ if err != nil {
584
+ panic (err )
585
+ }
586
+ reflectionv1 .RegisterReflectionServiceServer (app .GRPCQueryRouter (), reflectionSvc )
554
587
555
- cfg := module .NewConfigurator (app .appCodec , app .MsgServiceRouter (), app .GRPCQueryRouter ())
556
- app .mm .RegisterServices (cfg )
588
+ // create the simulation manager and define the order of the modules for deterministic simulations
589
+ overrideModules := map [string ]module.AppModuleSimulation {
590
+ dclauthmoduletypes .ModuleName : dclauthModule }
591
+ app .sm = module .NewSimulationManagerFromAppModules (app .mm .Modules , overrideModules )
592
+ app .sm .RegisterStoreDecoders ()
557
593
558
594
// initialize stores
559
595
app .MountKVStores (keys )
@@ -627,7 +663,7 @@ func New(
627
663
app .UpgradeKeeper .SetUpgradeHandler (
628
664
"v1.3" ,
629
665
func (ctx sdk.Context , plan upgradetypes.Plan , fromVM module.VersionMap ) (module.VersionMap , error ) {
630
- return app .mm .RunMigrations (ctx , cfg , fromVM )
666
+ return app .mm .RunMigrations (ctx , app . configurator , fromVM )
631
667
},
632
668
)
633
669
@@ -650,7 +686,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
650
686
// InitChainer application update at chain initialization.
651
687
func (app * App ) InitChainer (ctx sdk.Context , req abci.RequestInitChain ) abci.ResponseInitChain {
652
688
var genesisState GenesisState
653
- if err := tmjson .Unmarshal (req .AppStateBytes , & genesisState ); err != nil {
689
+ if err := json .Unmarshal (req .AppStateBytes , & genesisState ); err != nil {
654
690
panic (err )
655
691
}
656
692
app .UpgradeKeeper .SetModuleVersionMap (ctx , app .mm .GetVersionMap ())
@@ -699,21 +735,21 @@ func (app *App) InterfaceRegistry() types.InterfaceRegistry {
699
735
// GetKey returns the KVStoreKey for the provided store key.
700
736
//
701
737
// NOTE: This is solely to be used for testing purposes.
702
- func (app * App ) GetKey (storeKey string ) * sdk .KVStoreKey {
738
+ func (app * App ) GetKey (storeKey string ) * storetypes .KVStoreKey {
703
739
return app .keys [storeKey ]
704
740
}
705
741
706
742
// GetTKey returns the TransientStoreKey for the provided store key.
707
743
//
708
744
// NOTE: This is solely to be used for testing purposes.
709
- func (app * App ) GetTKey (storeKey string ) * sdk .TransientStoreKey {
745
+ func (app * App ) GetTKey (storeKey string ) * storetypes .TransientStoreKey {
710
746
return app .tkeys [storeKey ]
711
747
}
712
748
713
749
// GetMemKey returns the MemStoreKey for the provided mem key.
714
750
//
715
751
// NOTE: This is solely used for testing purposes.
716
- func (app * App ) GetMemKey (storeKey string ) * sdk .MemoryStoreKey {
752
+ func (app * App ) GetMemKey (storeKey string ) * storetypes .MemoryStoreKey {
717
753
return app .memKeys [storeKey ]
718
754
}
719
755
@@ -730,23 +766,19 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
730
766
// API server.
731
767
func (app * App ) RegisterAPIRoutes (apiSvr * api.Server , apiConfig config.APIConfig ) {
732
768
clientCtx := apiSvr .ClientCtx
733
- rpc .RegisterRoutes (clientCtx , apiSvr .Router )
734
-
735
- // Register legacy tx routes.
736
- authrest .RegisterTxRoutes (clientCtx , apiSvr .Router )
737
769
// Register new tx routes from grpc-gateway.
738
770
authtx .RegisterGRPCGatewayRoutes (clientCtx , apiSvr .GRPCGatewayRouter )
739
771
740
772
// Register new tendermint queries routes from grpc-gateway.
741
773
tmservice .RegisterGRPCGatewayRoutes (clientCtx , apiSvr .GRPCGatewayRouter )
742
774
743
775
// Register legacy and grpc-gateway routes for all modules.
744
- ModuleBasics .RegisterRESTRoutes (clientCtx , apiSvr .Router )
745
776
ModuleBasics .RegisterGRPCGatewayRoutes (clientCtx , apiSvr .GRPCGatewayRouter )
746
777
747
- // register app's OpenAPI routes.
748
- apiSvr .Router .Handle ("/static/openapi.yml" , http .FileServer (http .FS (docs .Docs )))
749
- apiSvr .Router .HandleFunc ("/" , openapiconsole .Handler (Name , "/static/openapi.yml" ))
778
+ // register swagger API from root so that other applications can override easily
779
+ if err := server .RegisterSwaggerAPI (apiSvr .ClientCtx , apiSvr .Router , apiConfig .Swagger ); err != nil {
780
+ panic (err )
781
+ }
750
782
}
751
783
752
784
// RegisterTxService implements the Application.RegisterTxService method.
@@ -756,21 +788,31 @@ func (app *App) RegisterTxService(clientCtx client.Context) {
756
788
757
789
// RegisterTendermintService implements the Application.RegisterTendermintService method.
758
790
func (app * App ) RegisterTendermintService (clientCtx client.Context ) {
759
- tmservice .RegisterTendermintService (app .BaseApp .GRPCQueryRouter (), clientCtx , app .interfaceRegistry )
791
+ tmservice .RegisterTendermintService (
792
+ clientCtx ,
793
+ app .BaseApp .GRPCQueryRouter (),
794
+ app .interfaceRegistry ,
795
+ app .Query ,
796
+ )
760
797
}
761
798
762
- // GetMaccPerms returns a copy of the module account permissions.
763
- func GetMaccPerms () map [string ][]string {
764
- dupMaccPerms := make (map [string ][]string )
765
- for k , v := range maccPerms {
766
- dupMaccPerms [k ] = v
767
- }
799
+ // TxConfig returns App's TxConfig.
800
+ func (app * App ) TxConfig () client.TxConfig {
801
+ return app .txConfig
802
+ }
803
+
804
+ // Configurator get app configurator
805
+ func (app * App ) Configurator () module.Configurator {
806
+ return app .configurator
807
+ }
768
808
769
- return dupMaccPerms
809
+ // ModuleManager returns the app ModuleManager
810
+ func (app * App ) ModuleManager () * module.Manager {
811
+ return app .mm
770
812
}
771
813
772
814
// initParamsKeeper init params keeper and its subspaces.
773
- func initParamsKeeper (appCodec codec.BinaryCodec , legacyAmino * codec.LegacyAmino , key , tkey sdk .StoreKey ) paramskeeper.Keeper {
815
+ func initParamsKeeper (appCodec codec.BinaryCodec , legacyAmino * codec.LegacyAmino , key , tkey storetypes .StoreKey ) paramskeeper.Keeper {
774
816
paramsKeeper := paramskeeper .NewKeeper (appCodec , legacyAmino , key , tkey )
775
817
776
818
paramsKeeper .Subspace (upgradetypes .ModuleName )
0 commit comments