ExportAppStateAndValidators exports the state of the application for a genesis file.
( forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string, )
| 28 | // ExportAppStateAndValidators exports the state of the application for a genesis |
| 29 | // file. |
| 30 | func (app *AkashApp) ExportAppStateAndValidators( |
| 31 | forZeroHeight bool, |
| 32 | jailAllowedAddrs []string, |
| 33 | modulesToExport []string, |
| 34 | ) (servertypes.ExportedApp, error) { |
| 35 | // as if they could withdraw from the start of the next block |
| 36 | ctx := app.NewContextLegacy(true, cmproto.Header{Height: app.LastBlockHeight()}) |
| 37 | |
| 38 | // We export at last height + 1, because that's the height at which |
| 39 | // Tendermint will start InitChain. |
| 40 | height := app.LastBlockHeight() + 1 |
| 41 | |
| 42 | if forZeroHeight { |
| 43 | height = 0 |
| 44 | app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) |
| 45 | } |
| 46 | |
| 47 | genState, err := app.MM.ExportGenesisForModules(ctx, app.cdc, modulesToExport) |
| 48 | if err != nil { |
| 49 | return servertypes.ExportedApp{}, err |
| 50 | } |
| 51 | |
| 52 | appState, err := json.MarshalIndent(genState, "", " ") |
| 53 | if err != nil { |
| 54 | return servertypes.ExportedApp{}, err |
| 55 | } |
| 56 | |
| 57 | validators, err := staking.WriteValidators(ctx, app.Keepers.Cosmos.Staking) |
| 58 | if err != nil { |
| 59 | return servertypes.ExportedApp{}, err |
| 60 | } |
| 61 | |
| 62 | return servertypes.ExportedApp{ |
| 63 | AppState: appState, |
| 64 | Validators: validators, |
| 65 | Height: height, |
| 66 | ConsensusParams: app.GetConsensusParams(ctx), |
| 67 | }, nil |
| 68 | } |
| 69 | |
| 70 | // prepForZeroHeightGenesis prepare for fresh start at zero height |
| 71 | // NOTE zero height genesis is a temporary feature that will be deprecated |