From 294f7677a5bf621b32a5e7eb8e9812a537474f7e Mon Sep 17 00:00:00 2001 From: caseylove Date: Mon, 13 Jan 2025 03:20:19 +0000 Subject: [PATCH] cherry pick all reference PRs --- x/accounts/module.go | 8 +++- x/bank/types/genesis.go | 7 ++- x/bank/v2/module.go | 9 ++-- x/circuit/module.go | 8 +++- x/consensus/module.go | 2 +- x/distribution/migrations/v4/migrate.go | 7 ++- x/distribution/module.go | 8 +++- x/distribution/simulation/decoder.go | 58 ++++++++++++++++++------- x/epochs/module.go | 8 +++- x/evidence/module.go | 8 +++- x/feegrant/migrations/v2/store.go | 2 +- x/feegrant/module/module.go | 8 +++- x/feegrant/simulation/decoder.go | 10 +++-- x/genutil/depinject.go | 2 +- x/genutil/module.go | 12 +++-- x/genutil/types/genesis_state.go | 11 +++-- x/group/internal/orm/types.go | 2 +- x/group/keeper/genesis.go | 7 +-- x/group/module/module.go | 8 +++- x/group/simulation/decoder.go | 42 +++++++++++++----- x/mint/module.go | 8 +++- x/nft/module/module.go | 8 +++- x/nft/simulation/decoder.go | 18 +++++--- x/protocolpool/module.go | 8 +++- x/slashing/migrations/v4/migrate.go | 10 +++-- x/staking/migrations/v5/store.go | 3 +- x/staking/migrations/v6/store.go | 3 +- x/staking/module.go | 12 +++-- x/staking/simulation/decoder.go | 58 ++++++++++++++++++------- x/staking/types/delegation.go | 20 +++++++-- x/staking/types/genesis.go | 6 ++- x/staking/types/validator.go | 8 +++- 32 files changed, 282 insertions(+), 107 deletions(-) diff --git a/x/accounts/module.go b/x/accounts/module.go index 978d6b9cb7da..22c353d9ed8d 100644 --- a/x/accounts/module.go +++ b/x/accounts/module.go @@ -9,12 +9,12 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/schema" "cosmossdk.io/x/accounts/cli" v1 "cosmossdk.io/x/accounts/v1" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/msgservice" ) @@ -66,7 +66,11 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // App module genesis func (am AppModule) DefaultGenesis() json.RawMessage { - return am.cdc.MustMarshalJSON(&v1.GenesisState{}) + data, err := am.cdc.MarshalJSON(&v1.GenesisState{}) + if err != nil { + panic(err) + } + return data } func (am AppModule) ValidateGenesis(message json.RawMessage) error { diff --git a/x/bank/types/genesis.go b/x/bank/types/genesis.go index 6f10e7713239..58e86c87c4e1 100644 --- a/x/bank/types/genesis.go +++ b/x/bank/types/genesis.go @@ -5,7 +5,8 @@ import ( "errors" "fmt" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -101,7 +102,9 @@ func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.R 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 diff --git a/x/bank/v2/module.go b/x/bank/v2/module.go index 99d5ab2ab7d4..c59c6403b8be 100644 --- a/x/bank/v2/module.go +++ b/x/bank/v2/module.go @@ -8,12 +8,11 @@ import ( "github.com/spf13/cobra" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/x/bank/v2/client/cli" "cosmossdk.io/x/bank/v2/keeper" "cosmossdk.io/x/bank/v2/types" - - "github.com/cosmos/cosmos-sdk/codec" ) // ConsensusVersion defines the current x/bank/v2 module consensus version. @@ -58,7 +57,11 @@ func (AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar) { // DefaultGenesis returns default genesis state as raw bytes for the bank 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 bank module. diff --git a/x/circuit/module.go b/x/circuit/module.go index da69333716bf..00930c95b29e 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" "cosmossdk.io/schema" @@ -19,7 +20,6 @@ import ( "cosmossdk.io/x/circuit/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -81,7 +81,11 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // DefaultGenesis returns default genesis state as raw bytes for the circuit 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 circuit module. diff --git a/x/consensus/module.go b/x/consensus/module.go index 7a21619980be..ac3d159fddaf 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -9,13 +9,13 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/schema" "cosmossdk.io/x/consensus/keeper" "cosmossdk.io/x/consensus/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" ) diff --git a/x/distribution/migrations/v4/migrate.go b/x/distribution/migrations/v4/migrate.go index 1ecfd4a2d8f6..ee816a607db3 100644 --- a/x/distribution/migrations/v4/migrate.go +++ b/x/distribution/migrations/v4/migrate.go @@ -7,9 +7,9 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/store" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -46,6 +46,9 @@ func GetPreviousProposerConsAddr(ctx context.Context, storeService store.KVStore // SetPreviousProposerConsAddr set the proposer public key for this block. func SetPreviousProposerConsAddr(ctx context.Context, storeService store.KVStoreService, cdc codec.BinaryCodec, consAddr sdk.ConsAddress) error { kvStore := storeService.OpenKVStore(ctx) - bz := cdc.MustMarshal(&gogotypes.BytesValue{Value: consAddr}) + bz, err := cdc.Marshal(&gogotypes.BytesValue{Value: consAddr}) + if err != nil { + panic(err) + } return kvStore.Set(OldProposerKey, bz) } diff --git a/x/distribution/module.go b/x/distribution/module.go index 3d284d44621c..058dd1c22125 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/schema" "cosmossdk.io/x/distribution/client/cli" @@ -19,7 +20,6 @@ import ( "cosmossdk.io/x/distribution/types" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simsx" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -115,7 +115,11 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error { // DefaultGenesis returns default genesis state as raw bytes for the distribution 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 distribution module. diff --git a/x/distribution/simulation/decoder.go b/x/distribution/simulation/decoder.go index 0373ce40d87f..c5bc9a879fce 100644 --- a/x/distribution/simulation/decoder.go +++ b/x/distribution/simulation/decoder.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/codec" "cosmossdk.io/x/distribution/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" ) @@ -18,14 +18,22 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.FeePoolKey): var feePoolA, feePoolB types.FeePool - cdc.MustUnmarshal(kvA.Value, &feePoolA) - cdc.MustUnmarshal(kvB.Value, &feePoolB) + if err := cdc.Unmarshal(kvA.Value, &feePoolA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &feePoolB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", feePoolA, feePoolB) case bytes.Equal(kvA.Key[:1], types.ValidatorOutstandingRewardsPrefix): var rewardsA, rewardsB types.ValidatorOutstandingRewards - cdc.MustUnmarshal(kvA.Value, &rewardsA) - cdc.MustUnmarshal(kvB.Value, &rewardsB) + if err := cdc.Unmarshal(kvA.Value, &rewardsA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &rewardsB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.DelegatorWithdrawAddrPrefix): @@ -33,32 +41,52 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { case bytes.Equal(kvA.Key[:1], types.DelegatorStartingInfoPrefix): var infoA, infoB types.DelegatorStartingInfo - cdc.MustUnmarshal(kvA.Value, &infoA) - cdc.MustUnmarshal(kvB.Value, &infoB) + if err := cdc.Unmarshal(kvA.Value, &infoA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &infoB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", infoA, infoB) case bytes.Equal(kvA.Key[:1], types.ValidatorHistoricalRewardsPrefix): var rewardsA, rewardsB types.ValidatorHistoricalRewards - cdc.MustUnmarshal(kvA.Value, &rewardsA) - cdc.MustUnmarshal(kvB.Value, &rewardsB) + if err := cdc.Unmarshal(kvA.Value, &rewardsA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &rewardsB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.ValidatorCurrentRewardsPrefix): var rewardsA, rewardsB types.ValidatorCurrentRewards - cdc.MustUnmarshal(kvA.Value, &rewardsA) - cdc.MustUnmarshal(kvB.Value, &rewardsB) + if err := cdc.Unmarshal(kvA.Value, &rewardsA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &rewardsB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", rewardsA, rewardsB) case bytes.Equal(kvA.Key[:1], types.ValidatorAccumulatedCommissionPrefix): var commissionA, commissionB types.ValidatorAccumulatedCommission - cdc.MustUnmarshal(kvA.Value, &commissionA) - cdc.MustUnmarshal(kvB.Value, &commissionB) + if err := cdc.Unmarshal(kvA.Value, &commissionA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &commissionB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", commissionA, commissionB) case bytes.Equal(kvA.Key[:1], types.ValidatorSlashEventPrefix): var eventA, eventB types.ValidatorSlashEvent - cdc.MustUnmarshal(kvA.Value, &eventA) - cdc.MustUnmarshal(kvB.Value, &eventB) + if err := cdc.Unmarshal(kvA.Value, &eventA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &eventB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", eventA, eventB) default: diff --git a/x/epochs/module.go b/x/epochs/module.go index aeb7947b4ec1..6846253438e4 100644 --- a/x/epochs/module.go +++ b/x/epochs/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/schema" "cosmossdk.io/x/epochs/keeper" @@ -17,7 +18,6 @@ import ( "cosmossdk.io/x/epochs/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -75,7 +75,11 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // DefaultGenesis returns the epochs module's default genesis state. func (am AppModule) DefaultGenesis() json.RawMessage { - return am.cdc.MustMarshalJSON(types.DefaultGenesis()) + data, err := am.cdc.MarshalJSON(types.DefaultGenesis()) + if err != nil { + panic(err) + } + return data } // ValidateGenesis performs genesis state validation for the epochs module. diff --git a/x/evidence/module.go b/x/evidence/module.go index 0327a83915ef..ee89003ff97d 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/comet" "cosmossdk.io/core/registry" eviclient "cosmossdk.io/x/evidence/client" @@ -19,7 +20,6 @@ import ( "cosmossdk.io/x/evidence/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -100,7 +100,11 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // DefaultGenesis returns the evidence module's default genesis state. 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 evidence module. diff --git a/x/feegrant/migrations/v2/store.go b/x/feegrant/migrations/v2/store.go index 93551a4ed99e..4643fc4441f2 100644 --- a/x/feegrant/migrations/v2/store.go +++ b/x/feegrant/migrations/v2/store.go @@ -4,11 +4,11 @@ import ( "context" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/store" "cosmossdk.io/store/prefix" "cosmossdk.io/x/feegrant" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" ) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 2e22fef937bc..05ec0d4dd355 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/errors" "cosmossdk.io/x/feegrant" @@ -17,7 +18,6 @@ import ( "cosmossdk.io/x/feegrant/keeper" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -103,7 +103,11 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error { // DefaultGenesis returns default genesis state as raw bytes for the feegrant module. func (am AppModule) DefaultGenesis() json.RawMessage { - return am.cdc.MustMarshalJSON(feegrant.DefaultGenesisState()) + data, err := am.cdc.MarshalJSON(feegrant.DefaultGenesisState()) + if err != nil { + panic(err) + } + return data } // ValidateGenesis performs genesis state validation for the feegrant module. diff --git a/x/feegrant/simulation/decoder.go b/x/feegrant/simulation/decoder.go index c1b4eedeb478..e99b39851b32 100644 --- a/x/feegrant/simulation/decoder.go +++ b/x/feegrant/simulation/decoder.go @@ -4,9 +4,9 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/codec" "cosmossdk.io/x/feegrant" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" ) @@ -17,8 +17,12 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], feegrant.FeeAllowanceKeyPrefix): var grantA, grantB feegrant.Grant - cdc.MustUnmarshal(kvA.Value, &grantA) - cdc.MustUnmarshal(kvB.Value, &grantB) + if err := cdc.Unmarshal(kvA.Value, &grantA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &grantB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", grantA, grantB) default: panic(fmt.Sprintf("invalid feegrant key %X", kvA.Key)) diff --git a/x/genutil/depinject.go b/x/genutil/depinject.go index c23aba5bf74b..ed026343a824 100644 --- a/x/genutil/depinject.go +++ b/x/genutil/depinject.go @@ -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" ) diff --git a/x/genutil/module.go b/x/genutil/module.go index 18ebc6a06c6c..5d5e35b4ff92 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -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" ) @@ -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..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" - "github.com/cosmos/cosmos-sdk/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 } diff --git a/x/group/internal/orm/types.go b/x/group/internal/orm/types.go index 11d113cd68a9..554520084c55 100644 --- a/x/group/internal/orm/types.go +++ b/x/group/internal/orm/types.go @@ -9,12 +9,12 @@ import ( "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/core/codec" storetypes "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/group/errors" "cosmossdk.io/x/group/internal/orm/prefixstore" - "github.com/cosmos/cosmos-sdk/codec" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" ) diff --git a/x/group/keeper/genesis.go b/x/group/keeper/genesis.go index 8c30ee85e71e..e26d2420c5f9 100644 --- a/x/group/keeper/genesis.go +++ b/x/group/keeper/genesis.go @@ -4,16 +4,17 @@ import ( "context" "encoding/json" + "cosmossdk.io/core/codec" "cosmossdk.io/errors" "cosmossdk.io/x/group" - - "github.com/cosmos/cosmos-sdk/codec" ) // InitGenesis initializes the group module's genesis state. func (k Keeper) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) error { var genesisState group.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) + if err := cdc.UnmarshalJSON(data, &genesisState); err != nil { + panic(err) + } store := k.KVStoreService.OpenKVStore(ctx) diff --git a/x/group/module/module.go b/x/group/module/module.go index 5ffe3fe6234b..e1d467ef8fde 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/x/group" "cosmossdk.io/x/group/client/cli" @@ -17,7 +18,6 @@ import ( "cosmossdk.io/x/group/simulation" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simsx" "github.com/cosmos/cosmos-sdk/types/module" @@ -118,7 +118,11 @@ func (am AppModule) EndBlock(ctx context.Context) error { // DefaultGenesis returns default genesis state as raw bytes for the group module. func (am AppModule) DefaultGenesis() json.RawMessage { - return am.cdc.MustMarshalJSON(group.NewGenesisState()) + data, err := am.cdc.MarshalJSON(group.NewGenesisState()) + if err != nil { + panic(err) + } + return data } // ValidateGenesis performs genesis state validation for the group module. diff --git a/x/group/simulation/decoder.go b/x/group/simulation/decoder.go index e1816520ae3c..e7cc0a95ab35 100644 --- a/x/group/simulation/decoder.go +++ b/x/group/simulation/decoder.go @@ -4,10 +4,10 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/codec" "cosmossdk.io/x/group" "cosmossdk.io/x/group/keeper" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" ) @@ -19,36 +19,56 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { case bytes.Equal(kvA.Key[:1], []byte{keeper.GroupTablePrefix}): var groupA, groupB group.GroupInfo - cdc.MustUnmarshal(kvA.Value, &groupA) - cdc.MustUnmarshal(kvB.Value, &groupB) + if err := cdc.Unmarshal(kvA.Value, &groupA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &groupB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", groupA, groupB) case bytes.Equal(kvA.Key[:1], []byte{keeper.GroupMemberTablePrefix}): var memberA, memberB group.GroupMember - cdc.MustUnmarshal(kvA.Value, &memberA) - cdc.MustUnmarshal(kvB.Value, &memberB) + if err := cdc.Unmarshal(kvA.Value, &memberA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &memberB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", memberA, memberB) case bytes.Equal(kvA.Key[:1], []byte{keeper.GroupPolicyTablePrefix}): var accA, accB group.GroupPolicyInfo - cdc.MustUnmarshal(kvA.Value, &accA) - cdc.MustUnmarshal(kvB.Value, &accB) + if err := cdc.Unmarshal(kvA.Value, &accA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &accB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", accA, accB) case bytes.Equal(kvA.Key[:1], []byte{keeper.ProposalTablePrefix}): var propA, propB group.Proposal - cdc.MustUnmarshal(kvA.Value, &propA) - cdc.MustUnmarshal(kvB.Value, &propB) + if err := cdc.Unmarshal(kvA.Value, &propA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &propB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", propA, propB) case bytes.Equal(kvA.Key[:1], []byte{keeper.VoteTablePrefix}): var voteA, voteB group.Vote - cdc.MustUnmarshal(kvA.Value, &voteA) - cdc.MustUnmarshal(kvB.Value, &voteB) + if err := cdc.Unmarshal(kvA.Value, &voteA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &voteB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", voteA, voteB) default: diff --git a/x/mint/module.go b/x/mint/module.go index 882f7b7f91c4..ff041541d526 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/schema" "cosmossdk.io/x/mint/keeper" @@ -17,7 +18,6 @@ import ( "cosmossdk.io/x/mint/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simsx" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -110,7 +110,11 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error { // DefaultGenesis returns default genesis state as raw bytes for the mint 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 mint module. diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 16b82baf2a23..a3622d27f65d 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -8,6 +8,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/errors" "cosmossdk.io/x/nft" @@ -15,7 +16,6 @@ import ( "cosmossdk.io/x/nft/simulation" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simsx" "github.com/cosmos/cosmos-sdk/types/module" @@ -85,7 +85,11 @@ func (AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *gwr // DefaultGenesis returns default genesis state as raw bytes for the nft module. func (am AppModule) DefaultGenesis() json.RawMessage { - return am.cdc.MustMarshalJSON(nft.DefaultGenesisState()) + data, err := am.cdc.MarshalJSON(nft.DefaultGenesisState()) + if err != nil { + panic(err) + } + return data } // ValidateGenesis performs genesis state validation for the nft module. diff --git a/x/nft/simulation/decoder.go b/x/nft/simulation/decoder.go index 7c7fcef4a0bf..5290af153243 100644 --- a/x/nft/simulation/decoder.go +++ b/x/nft/simulation/decoder.go @@ -4,10 +4,10 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/codec" "cosmossdk.io/x/nft" "cosmossdk.io/x/nft/keeper" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" ) @@ -19,13 +19,21 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], keeper.ClassKey): var classA, classB nft.Class - cdc.MustUnmarshal(kvA.Value, &classA) - cdc.MustUnmarshal(kvB.Value, &classB) + if err := cdc.Unmarshal(kvA.Value, &classA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &classB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", classA, classB) case bytes.Equal(kvA.Key[:1], keeper.NFTKey): var nftA, nftB nft.NFT - cdc.MustUnmarshal(kvA.Value, &nftA) - cdc.MustUnmarshal(kvB.Value, &nftB) + if err := cdc.Unmarshal(kvA.Value, &nftA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &nftB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", nftA, nftB) case bytes.Equal(kvA.Key[:1], keeper.NFTOfClassByOwnerKey): return fmt.Sprintf("%v\n%v", kvA.Value, kvB.Value) diff --git a/x/protocolpool/module.go b/x/protocolpool/module.go index f594459d1756..ffbb57598c9f 100644 --- a/x/protocolpool/module.go +++ b/x/protocolpool/module.go @@ -9,12 +9,12 @@ import ( "google.golang.org/grpc" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/x/protocolpool/keeper" "cosmossdk.io/x/protocolpool/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -80,7 +80,11 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // DefaultGenesis returns default genesis state as raw bytes for the protocolpool 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 protocolpool module. diff --git a/x/slashing/migrations/v4/migrate.go b/x/slashing/migrations/v4/migrate.go index 454995300dda..5387c4bec926 100644 --- a/x/slashing/migrations/v4/migrate.go +++ b/x/slashing/migrations/v4/migrate.go @@ -7,11 +7,11 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" "cosmossdk.io/core/address" + "cosmossdk.io/core/codec" "cosmossdk.io/errors" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/slashing/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -74,7 +74,9 @@ func iterateValidatorSigningInfos( for ; iter.Valid(); iter.Next() { addr := ValidatorSigningInfoAddress(iter.Key()) var info types.ValidatorSigningInfo - cdc.MustUnmarshal(iter.Value(), &info) + if err := cdc.Unmarshal(iter.Value(), &info); err != nil { + panic(err) + } if cb(addr, info) { break @@ -97,7 +99,9 @@ func iterateValidatorMissedBlockBitArray( continue } - cdc.MustUnmarshal(bz, &missed) + if err := cdc.Unmarshal(bz, &missed); err != nil { + panic(err) + } if cb(i, missed.Value) { break } diff --git a/x/staking/migrations/v5/store.go b/x/staking/migrations/v5/store.go index adc7a5c52a68..42fbbceed6d4 100644 --- a/x/staking/migrations/v5/store.go +++ b/x/staking/migrations/v5/store.go @@ -5,11 +5,10 @@ import ( "fmt" "strconv" + "cosmossdk.io/core/codec" "cosmossdk.io/core/log" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" ) func migrateDelegationsByValidatorIndex(store storetypes.KVStore) error { diff --git a/x/staking/migrations/v6/store.go b/x/staking/migrations/v6/store.go index 98b4cb446faa..46aa46e68abe 100644 --- a/x/staking/migrations/v6/store.go +++ b/x/staking/migrations/v6/store.go @@ -3,9 +3,8 @@ package v6 import ( "context" + "cosmossdk.io/core/codec" storetypes "cosmossdk.io/store/types" - - "github.com/cosmos/cosmos-sdk/codec" ) // MigrateStore performs in-place store migrations from v5 to v6. diff --git a/x/staking/module.go b/x/staking/module.go index d21b3c396848..786fb4fd8699 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/collections" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/core/registry" "cosmossdk.io/depinject" "cosmossdk.io/schema" @@ -19,7 +20,6 @@ import ( "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -119,7 +119,11 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error { // DefaultGenesis returns default genesis state as raw bytes for the staking 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 staking module. @@ -135,7 +139,9 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { // InitGenesis performs genesis initialization for the staking module. func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]appmodule.ValidatorUpdate, error) { var genesisState types.GenesisState - am.cdc.MustUnmarshalJSON(data, &genesisState) + if err := am.cdc.UnmarshalJSON(data, &genesisState); err != nil { + panic(err) + } return am.keeper.InitGenesis(ctx, &genesisState) } diff --git a/x/staking/simulation/decoder.go b/x/staking/simulation/decoder.go index fd7b09da7bc4..a856edb015f4 100644 --- a/x/staking/simulation/decoder.go +++ b/x/staking/simulation/decoder.go @@ -4,10 +4,10 @@ import ( "bytes" "fmt" + "cosmossdk.io/core/codec" "cosmossdk.io/math" "cosmossdk.io/x/staking/types" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" ) @@ -30,8 +30,12 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { case bytes.Equal(kvA.Key[:1], types.ValidatorsKey): var validatorA, validatorB types.Validator - cdc.MustUnmarshal(kvA.Value, &validatorA) - cdc.MustUnmarshal(kvB.Value, &validatorB) + if err := cdc.Unmarshal(kvA.Value, &validatorA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &validatorB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", validatorA, validatorB) case bytes.Equal(kvA.Key[:1], types.LastValidatorPowerKey), @@ -42,45 +46,69 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { case bytes.Equal(kvA.Key[:1], types.DelegationKey): var delegationA, delegationB types.Delegation - cdc.MustUnmarshal(kvA.Value, &delegationA) - cdc.MustUnmarshal(kvB.Value, &delegationB) + if err := cdc.Unmarshal(kvA.Value, &delegationA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &delegationB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", delegationA, delegationB) case bytes.Equal(kvA.Key[:1], types.UnbondingDelegationKey), bytes.Equal(kvA.Key[:1], types.UnbondingDelegationByValIndexKey): var ubdA, ubdB types.UnbondingDelegation - cdc.MustUnmarshal(kvA.Value, &ubdA) - cdc.MustUnmarshal(kvB.Value, &ubdB) + if err := cdc.Unmarshal(kvA.Value, &ubdA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &ubdB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", ubdA, ubdB) case bytes.Equal(kvA.Key[:1], types.RedelegationKey), bytes.Equal(kvA.Key[:1], types.RedelegationByValSrcIndexKey): var redA, redB types.Redelegation - cdc.MustUnmarshal(kvA.Value, &redA) - cdc.MustUnmarshal(kvB.Value, &redB) + if err := cdc.Unmarshal(kvA.Value, &redA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &redB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", redA, redB) case bytes.Equal(kvA.Key[:1], types.ParamsKey): var paramsA, paramsB types.Params - cdc.MustUnmarshal(kvA.Value, ¶msA) - cdc.MustUnmarshal(kvB.Value, ¶msB) + if err := cdc.Unmarshal(kvA.Value, ¶msA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, ¶msB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", paramsA, paramsB) case bytes.Equal(kvA.Key[:1], types.ValidatorConsPubKeyRotationHistoryKey): var historyA, historyB types.ConsPubKeyRotationHistory - cdc.MustUnmarshal(kvA.Value, &historyA) - cdc.MustUnmarshal(kvB.Value, &historyB) + if err := cdc.Unmarshal(kvA.Value, &historyA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &historyB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", historyA, historyB) case bytes.Equal(kvA.Key[:1], types.ValidatorConsensusKeyRotationRecordQueueKey): var historyA, historyB types.ValAddrsOfRotatedConsKeys - cdc.MustUnmarshal(kvA.Value, &historyA) - cdc.MustUnmarshal(kvB.Value, &historyB) + if err := cdc.Unmarshal(kvA.Value, &historyA); err != nil { + panic(err) + } + if err := cdc.Unmarshal(kvB.Value, &historyB); err != nil { + panic(err) + } return fmt.Sprintf("%v\n%v", historyA, historyB) default: diff --git a/x/staking/types/delegation.go b/x/staking/types/delegation.go index c7754d9a8412..b2a42f8b4c25 100644 --- a/x/staking/types/delegation.go +++ b/x/staking/types/delegation.go @@ -6,9 +6,9 @@ import ( "time" "cosmossdk.io/core/address" + "cosmossdk.io/core/codec" "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -26,7 +26,11 @@ func NewDelegation(delegatorAddr, validatorAddr string, shares math.LegacyDec) D // MustMarshalDelegation returns the delegation bytes. Panics if fails func MustMarshalDelegation(cdc codec.BinaryCodec, delegation Delegation) []byte { - return cdc.MustMarshal(&delegation) + data, err := cdc.Marshal(&delegation) + if err != nil { + panic(err) + } + return data } // MustUnmarshalDelegation return the unmarshaled delegation from bytes. @@ -143,7 +147,11 @@ func (ubd *UnbondingDelegation) RemoveEntry(i int64) { // return the unbonding delegation func MustMarshalUBD(cdc codec.BinaryCodec, ubd UnbondingDelegation) []byte { - return cdc.MustMarshal(&ubd) + data, err := cdc.Marshal(&ubd) + if err != nil { + panic(err) + } + return data } // unmarshal a unbonding delegation from a store value @@ -234,7 +242,11 @@ func (red *Redelegation) RemoveEntry(i int64) { // MustMarshalRED returns the Redelegation bytes. Panics if fails. func MustMarshalRED(cdc codec.BinaryCodec, red Redelegation) []byte { - return cdc.MustMarshal(&red) + data, err := cdc.Marshal(&red) + if err != nil { + panic(err) + } + return data } // MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails. diff --git a/x/staking/types/genesis.go b/x/staking/types/genesis.go index e3534fc4ea58..0f992824200f 100644 --- a/x/staking/types/genesis.go +++ b/x/staking/types/genesis.go @@ -5,7 +5,7 @@ import ( gogoprotoany "github.com/cosmos/gogoproto/types/any" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/codec" ) // NewGenesisState creates a new GenesisState instance @@ -30,7 +30,9 @@ func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.R 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 diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index b626d2e2ea0b..16ff0737026a 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -12,10 +12,10 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/codec" "cosmossdk.io/errors" "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -152,7 +152,11 @@ func (v Validators) UnpackInterfaces(c gogoprotoany.AnyUnpacker) error { // return the redelegation func MustMarshalValidator(cdc codec.BinaryCodec, validator *Validator) []byte { - return cdc.MustMarshal(validator) + data, err := cdc.Marshal(validator) + if err != nil { + panic(err) + } + return data } // unmarshal a redelegation from a store value