/
genesis.go
37 lines (30 loc) · 1.02 KB
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package server
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/orm/types/ormjson"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)
// InitGenesis performs genesis initialization for the data module. It
// returns no validator updates.
func (s serverImpl) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) ([]abci.ValidatorUpdate, error) {
jsonSource, err := ormjson.NewRawMessageSource(data)
if err != nil {
return nil, err
}
err = s.db.ImportJSON(sdk.WrapSDKContext(ctx), jsonSource)
if err != nil {
return nil, err
}
return []abci.ValidatorUpdate{}, nil
}
// ExportGenesis will dump the data module state into a serializable GenesisState.
func (s serverImpl) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) {
jsonTarget := ormjson.NewRawMessageTarget()
err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), jsonTarget)
if err != nil {
return nil, err
}
return jsonTarget.JSON()
}