From 494556809defa6855728e4b2cb1c4201c80c0890 Mon Sep 17 00:00:00 2001 From: caseylove Date: Fri, 10 Jan 2025 11:45:37 +0800 Subject: [PATCH 1/2] chore(x/genutil): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec --- x/genutil/depinject.go | 2 +- x/genutil/module.go | 12 +++++++++--- x/genutil/types/genesis_state.go | 11 ++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/x/genutil/depinject.go b/x/genutil/depinject.go index c23aba5bf74b..d5db26f4dae5 100644 --- a/x/genutil/depinject.go +++ b/x/genutil/depinject.go @@ -6,8 +6,8 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" + "cosmossdk.io/core/codec" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) diff --git a/x/genutil/module.go b/x/genutil/module.go index 18ebc6a06c6c..3764ffa5268d 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -8,8 +8,8 @@ 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" ) @@ -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. @@ -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) } diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index a4c77593a01a..45eb9e84d779 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -7,7 +7,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -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 } @@ -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 } From 393ce1e4f0853623501db35798c68de647118e0a Mon Sep 17 00:00:00 2001 From: caseylove Date: Fri, 10 Jan 2025 11:48:58 +0800 Subject: [PATCH 2/2] fix lint --- x/genutil/depinject.go | 2 +- x/genutil/module.go | 2 +- x/genutil/types/genesis_state.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/genutil/depinject.go b/x/genutil/depinject.go index d5db26f4dae5..ed026343a824 100644 --- a/x/genutil/depinject.go +++ b/x/genutil/depinject.go @@ -3,10 +3,10 @@ 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" - "cosmossdk.io/core/codec" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) diff --git a/x/genutil/module.go b/x/genutil/module.go index 3764ffa5268d..5d5e35b4ff92 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -7,8 +7,8 @@ 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/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" diff --git a/x/genutil/types/genesis_state.go b/x/genutil/types/genesis_state.go index 45eb9e84d779..228616810ef9 100644 --- a/x/genutil/types/genesis_state.go +++ b/x/genutil/types/genesis_state.go @@ -5,9 +5,9 @@ import ( "fmt" "os" + "cosmossdk.io/core/codec" stakingtypes "cosmossdk.io/x/staking/types" - "cosmossdk.io/core/codec" sdk "github.com/cosmos/cosmos-sdk/types" )