Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(x/genutil): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec #23295

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/genutil/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package genutil
import (
modulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)

Expand Down
12 changes: 9 additions & 3 deletions x/genutil/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"cosmossdk.io/core/appmodule"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/codec"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
Expand Down Expand Up @@ -62,7 +62,11 @@ func (AppModule) Name() string {

// DefaultGenesis returns default genesis state as raw bytes for the genutil module.
func (am AppModule) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
data, err := am.cdc.MarshalJSON(types.DefaultGenesisState())
if err != nil {
panic(err)
}
return data
}

// ValidateGenesis performs genesis state validation for the genutil module.
Expand All @@ -79,7 +83,9 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error {
// InitGenesis is skipped in a server/v2 application as DecodeGenesisJSON takes precedence.
func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]module.ValidatorUpdate, error) {
var genesisState types.GenesisState
am.cdc.MustUnmarshalJSON(data, &genesisState)
if err := am.cdc.UnmarshalJSON(data, &genesisState); err != nil {
panic(err)
}
return InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig)
}

Expand Down
11 changes: 8 additions & 3 deletions x/genutil/types/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"os"

"cosmossdk.io/core/codec"
stakingtypes "cosmossdk.io/x/staking/types"

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

Expand Down Expand Up @@ -47,7 +47,9 @@ func NewGenesisStateFromTx(txJSONEncoder sdk.TxEncoder, genTxs []sdk.Tx) *Genesi
func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *GenesisState {
var genesisState GenesisState
if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
if err := cdc.UnmarshalJSON(appState[ModuleName], &genesisState); err != nil {
panic(err)
}
}
return &genesisState
}
Expand All @@ -56,7 +58,10 @@ func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.R
func SetGenesisStateInAppState(
cdc codec.JSONCodec, appState map[string]json.RawMessage, genesisState *GenesisState,
) map[string]json.RawMessage {
genesisStateBz := cdc.MustMarshalJSON(genesisState)
genesisStateBz, err := cdc.MarshalJSON(genesisState)
if err != nil {
panic(err)
}
appState[ModuleName] = genesisStateBz
return appState
}
Expand Down
Loading