@@ -3,27 +3,46 @@ package simapp
3
3
import (
4
4
"context"
5
5
6
+ "cosmossdk.io/runtime/v2/services"
7
+ "cosmossdk.io/x/staking"
8
+
6
9
v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2"
7
10
)
8
11
9
12
// ExportAppStateAndValidators exports the state of the application for a genesis
10
13
// file.
11
- func (app * SimApp [T ]) ExportAppStateAndValidators (jailAllowedAddrs []string ) (v2.ExportedApp , error ) {
12
- // as if they could withdraw from the start of the next block
14
+ // This is a demonstation of how to export a genesis file. Export may need extended at
15
+ // the user discretion for cleaning the genesis state at the end provided with jailAllowedAddrs
16
+ func (app * SimApp [T ]) ExportAppStateAndValidators (
17
+ jailAllowedAddrs []string ,
18
+ ) (v2.ExportedApp , error ) {
13
19
ctx := context .Background ()
20
+ var exportedApp v2.ExportedApp
14
21
15
22
latestHeight , err := app .LoadLatestHeight ()
16
23
if err != nil {
17
- return v2. ExportedApp {} , err
24
+ return exportedApp , err
18
25
}
19
26
20
27
genesis , err := app .ExportGenesis (ctx , latestHeight )
21
28
if err != nil {
22
- return v2.ExportedApp {}, err
29
+ return exportedApp , err
30
+ }
31
+
32
+ readerMap , err := app .GetStore ().StateAt (latestHeight )
33
+ if err != nil {
34
+ return exportedApp , err
35
+ }
36
+ genesisCtx := services .NewGenesisContext (readerMap )
37
+ err = genesisCtx .Read (ctx , func (ctx context.Context ) error {
38
+ exportedApp .Validators , err = staking .WriteValidators (ctx , app .StakingKeeper )
39
+ return err
40
+ })
41
+ if err != nil {
42
+ return exportedApp , err
23
43
}
24
44
25
- return v2.ExportedApp {
26
- AppState : genesis ,
27
- Height : int64 (latestHeight ),
28
- }, nil
45
+ exportedApp .AppState = genesis
46
+ exportedApp .Height = int64 (latestHeight )
47
+ return exportedApp , nil
29
48
}
0 commit comments