diff --git a/x/staking/migrations/v5/store.go b/x/staking/migrations/v5/store.go index adc7a5c52a68..530de8538897 100644 --- a/x/staking/migrations/v5/store.go +++ b/x/staking/migrations/v5/store.go @@ -9,7 +9,7 @@ import ( "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/codec" ) func migrateDelegationsByValidatorIndex(store storetypes.KVStore) error { diff --git a/x/staking/module.go b/x/staking/module.go index d21b3c396848..6654e88b21e4 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -19,7 +19,7 @@ import ( "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/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..67d7d0845814 100644 --- a/x/staking/simulation/decoder.go +++ b/x/staking/simulation/decoder.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" "cosmossdk.io/x/staking/types" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/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..031cd14067c5 100644 --- a/x/staking/types/delegation.go +++ b/x/staking/types/delegation.go @@ -8,7 +8,7 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/codec" + "cosmossdk.io/core/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.