Skip to content

Commit

Permalink
feat(x): decode modules genesis state for testnetify command (#1812)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed May 5, 2023
1 parent c4a4bb2 commit 63e8a64
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
15 changes: 15 additions & 0 deletions x/audit/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package audit

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"

Expand Down Expand Up @@ -29,3 +32,15 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
func DefaultGenesisState() *types.GenesisState {
return &types.GenesisState{}
}

// GetGenesisStateFromAppState returns x/audit 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
}
17 changes: 16 additions & 1 deletion x/deployment/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package deployment

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"

Expand All @@ -9,7 +12,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

// ValidateGenesis does validation check of the Genesis and return error incase of failure
// ValidateGenesis does validation check of the Genesis and return error in case of failure
func ValidateGenesis(data *types.GenesisState) error {
for _, record := range data.Deployments {
if err := record.Deployment.ID().Validate(); err != nil {
Expand Down Expand Up @@ -56,3 +59,15 @@ func ExportGenesis(ctx sdk.Context, k keeper.IKeeper) *types.GenesisState {
Params: params,
}
}

// GetGenesisStateFromAppState returns x/deployment 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
}
15 changes: 15 additions & 0 deletions x/inflation/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package inflation

import (
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/akash-network/node/x/inflation/keeper"
Expand Down Expand Up @@ -34,3 +37,15 @@ func ExportGenesis(ctx sdk.Context, k keeper.IKeeper) *types.GenesisState {
Params: params,
}
}

// GetGenesisStateFromAppState returns x/inflation 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
}
43 changes: 40 additions & 3 deletions x/market/genesis.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package market

import (
"github.com/akash-network/node/x/market/keeper"
types "github.com/akash-network/node/x/market/types/v1beta2"
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/akash-network/node/x/market/keeper"
types "github.com/akash-network/node/x/market/types/v1beta2"
)

// ValidateGenesis does validation check of the Genesis
func ValidateGenesis(data *types.GenesisState) error {
return data.Params.Validate()
if err := data.Params.Validate(); err != nil {
return err
}

return nil
}

// DefaultGenesisState returns default genesis state as raw bytes for the market
Expand All @@ -29,7 +38,35 @@ func InitGenesis(ctx sdk.Context, keeper keeper.IKeeper, data *types.GenesisStat
// 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 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
})

return &types.GenesisState{
Params: params,
Orders: orders,
Leases: leases,
}
}

// 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
}
34 changes: 30 additions & 4 deletions x/provider/genesis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package provider

import (
"github.com/akash-network/node/x/provider/keeper"
types "github.com/akash-network/node/x/provider/types/v1beta2"
"encoding/json"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/akash-network/node/x/provider/keeper"
types "github.com/akash-network/node/x/provider/types/v1beta2"
)

// ValidateGenesis does validation check of the Genesis and returns error incase of failure
// ValidateGenesis does validation check of the Genesis and returns error incase-of failure
func ValidateGenesis(data *types.GenesisState) error {
return nil
}
Expand All @@ -19,11 +24,32 @@ func InitGenesis(ctx sdk.Context, keeper keeper.IKeeper, data *types.GenesisStat

// ExportGenesis returns genesis state as raw bytes for the provider module
func ExportGenesis(ctx sdk.Context, k keeper.IKeeper) *types.GenesisState {
return &types.GenesisState{}
var providers []types.Provider

k.WithProviders(ctx, func(provider types.Provider) bool {
providers = append(providers, provider)
return true
})

return &types.GenesisState{
Providers: providers,
}
}

// DefaultGenesisState returns default genesis state as raw bytes for the provider
// module.
func DefaultGenesisState() *types.GenesisState {
return &types.GenesisState{}
}

// GetGenesisStateFromAppState returns x/provider 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
}

0 comments on commit 63e8a64

Please sign in to comment.