@@ -318,13 +318,10 @@ func newApp(
318
318
panic (err )
319
319
}
320
320
321
- homeDir := cast .ToString (appOpts .Get (flags .FlagHome ))
322
- chainID := cast .ToString (appOpts .Get (flags .FlagChainID ))
323
- if chainID == "" {
324
- chainID , err = evmdconfig .GetChainIDFromHome (homeDir )
325
- if err != nil {
326
- panic (err )
327
- }
321
+ // get the chain id
322
+ chainID , err := getChainIDFromOpts (appOpts )
323
+ if err != nil {
324
+ panic (err )
328
325
}
329
326
330
327
snapshotStore , err := sdkserver .GetSnapshotStore (appOpts )
@@ -399,15 +396,39 @@ func appExport(
399
396
viperAppOpts .Set (sdkserver .FlagInvCheckPeriod , 1 )
400
397
appOpts = viperAppOpts
401
398
399
+ // get the chain id
400
+ chainID , err := getChainIDFromOpts (appOpts )
401
+ if err != nil {
402
+ return servertypes.ExportedApp {}, err
403
+ }
404
+
402
405
if height != - 1 {
403
- exampleApp = evmd .NewExampleApp (logger , db , traceStore , false , appOpts , evmd .EvmAppOptions )
406
+ exampleApp = evmd .NewExampleApp (logger , db , traceStore , false , appOpts , evmd .EvmAppOptions , baseapp . SetChainID ( chainID ) )
404
407
405
408
if err := exampleApp .LoadHeight (height ); err != nil {
406
409
return servertypes.ExportedApp {}, err
407
410
}
408
411
} else {
409
- exampleApp = evmd .NewExampleApp (logger , db , traceStore , true , appOpts , evmd .EvmAppOptions )
412
+ exampleApp = evmd .NewExampleApp (logger , db , traceStore , true , appOpts , evmd .EvmAppOptions , baseapp . SetChainID ( chainID ) )
410
413
}
411
414
412
415
return exampleApp .ExportAppStateAndValidators (forZeroHeight , jailAllowedAddrs , modulesToExport )
413
416
}
417
+
418
+ // getChainIDFromOpts returns the chain Id from app Opts
419
+ // It first tries to get from the chainId flag, if not available
420
+ // it will load from home
421
+ func getChainIDFromOpts (appOpts servertypes.AppOptions ) (chainID string , err error ) {
422
+ // Get the chain Id from appOpts
423
+ chainID = cast .ToString (appOpts .Get (flags .FlagChainID ))
424
+ if chainID == "" {
425
+ // If not available load from home
426
+ homeDir := cast .ToString (appOpts .Get (flags .FlagHome ))
427
+ chainID , err = evmdconfig .GetChainIDFromHome (homeDir )
428
+ if err != nil {
429
+ return "" , err
430
+ }
431
+ }
432
+
433
+ return
434
+ }
0 commit comments