-
Notifications
You must be signed in to change notification settings - Fork 210
/
genesis.go
79 lines (62 loc) · 1.94 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package market
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
types "github.com/akash-network/akash-api/go/node/market/v1beta3"
"github.com/akash-network/node/x/market/keeper"
)
// ValidateGenesis does validation check of the Genesis
func ValidateGenesis(data *types.GenesisState) error {
if err := data.Params.Validate(); err != nil {
return err
}
return nil
}
// DefaultGenesisState returns default genesis state as raw bytes for the market
// module.
func DefaultGenesisState() *types.GenesisState {
return &types.GenesisState{
Params: types.DefaultParams(),
}
}
// InitGenesis initiate genesis state and return updated validator details
func InitGenesis(ctx sdk.Context, keeper keeper.IKeeper, data *types.GenesisState) []abci.ValidatorUpdate {
keeper.SetParams(ctx, data.Params)
return []abci.ValidatorUpdate{}
}
// ExportGenesis returns genesis state as raw bytes for the market module
func ExportGenesis(ctx sdk.Context, k keeper.IKeeper) *types.GenesisState {
params := k.GetParams(ctx)
var bids []types.Bid
var leases []types.Lease
var orders []types.Order
k.WithLeases(ctx, func(lease types.Lease) bool {
leases = append(leases, lease)
return false
})
k.WithOrders(ctx, func(order types.Order) bool {
orders = append(orders, order)
return false
})
k.WithBids(ctx, func(bid types.Bid) bool {
bids = append(bids, bid)
return false
})
return &types.GenesisState{
Params: params,
Orders: orders,
Leases: leases,
Bids: bids,
}
}
// GetGenesisStateFromAppState returns x/market GenesisState given raw application
// genesis state.
func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *types.GenesisState {
var genesisState types.GenesisState
if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
}
return &genesisState
}