|
7 | 7 | "github.com/cosmos/cosmos-sdk/codec" |
8 | 8 | sdk "github.com/cosmos/cosmos-sdk/types" |
9 | 9 | "github.com/cosmos/cosmos-sdk/types/module" |
| 10 | + "github.com/cosmos/cosmos-sdk/x/capability/types" |
10 | 11 |
|
11 | 12 | "github.com/gorilla/mux" |
12 | 13 | "github.com/spf13/cobra" |
@@ -44,7 +45,9 @@ func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { |
44 | 45 | } |
45 | 46 |
|
46 | 47 | // DefaultGenesis returns the capability module's default genesis state. |
47 | | -func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage { return []byte("{}") } |
| 48 | +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { |
| 49 | + return cdc.MustMarshalJSON(types.DefaultGenesis()) |
| 50 | +} |
48 | 51 |
|
49 | 52 | // ValidateGenesis performs genesis state validation for the capability module. |
50 | 53 | func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) error { return nil } |
@@ -98,16 +101,20 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} |
98 | 101 |
|
99 | 102 | // InitGenesis performs the capability module's genesis initialization It returns |
100 | 103 | // no validator updates. |
101 | | -func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { |
102 | | - // Initialize global index to 1 |
103 | | - am.keeper.InitializeIndex(ctx) |
| 104 | +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, gs json.RawMessage) []abci.ValidatorUpdate { |
| 105 | + var genState types.GenesisState |
| 106 | + // Initialize global index to index in genesis state |
| 107 | + cdc.MustUnmarshalJSON(gs, &genState) |
| 108 | + |
| 109 | + am.keeper.SetIndex(ctx, genState.Index) |
104 | 110 |
|
105 | 111 | return []abci.ValidatorUpdate{} |
106 | 112 | } |
107 | 113 |
|
108 | 114 | // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. |
109 | | -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { |
110 | | - return am.DefaultGenesis(cdc) |
| 115 | +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONMarshaler) json.RawMessage { |
| 116 | + index := am.keeper.GetLatestIndex(ctx) |
| 117 | + return cdc.MustMarshalJSON(types.GenesisState{index}) |
111 | 118 | } |
112 | 119 |
|
113 | 120 | // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. |
|
0 commit comments