-
Notifications
You must be signed in to change notification settings - Fork 172
/
genesis.go
61 lines (49 loc) · 1.41 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package clock
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/CosmosContracts/juno/v17/x/clock/keeper"
"github.com/CosmosContracts/juno/v17/x/clock/types"
)
// NewGenesisState - Create a new genesis state
func NewGenesisState(params types.Params) *types.GenesisState {
return &types.GenesisState{
Params: params,
}
}
// DefaultGenesisState - Return a default genesis state
func DefaultGenesisState() *types.GenesisState {
return NewGenesisState(types.DefaultParams())
}
// GetGenesisStateFromAppState returns x/auth GenesisState given raw application
// genesis state.
func GetGenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessage) *types.GenesisState {
var genesisState types.GenesisState
if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
}
return &genesisState
}
func ValidateGenesis(data types.GenesisState) error {
return data.Params.Validate()
}
// InitGenesis import module genesis
func InitGenesis(
ctx sdk.Context,
k keeper.Keeper,
data types.GenesisState,
) {
if err := ValidateGenesis(data); err != nil {
panic(err)
}
if err := k.SetParams(ctx, data.Params); err != nil {
panic(err)
}
}
// ExportGenesis export module state
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
}
}