Skip to content

Commit

Permalink
chore(x/gov, x/authz): use cosmossdk.io/core/codec instead of github.…
Browse files Browse the repository at this point in the history
…com/cosmos/cosmos-sdk/codec (backport #23292) (#23339)

Co-authored-by: DevOrbitlabs <[email protected]>
  • Loading branch information
mergify[bot] and hoank101 authored Jan 13, 2025
1 parent f2ec386 commit 348975e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion x/authz/migrations/v2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/store/prefix"
"cosmossdk.io/x/authz"
"cosmossdk.io/x/authz/internal/conv"

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

Expand Down
8 changes: 6 additions & 2 deletions x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/authz"
Expand All @@ -18,7 +19,6 @@ import (
"cosmossdk.io/x/authz/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"
Expand Down Expand Up @@ -110,7 +110,11 @@ func (AppModule) GetTxCmd() *cobra.Command {

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

// ValidateGenesis performs genesis state validation for the authz module.
Expand Down
18 changes: 13 additions & 5 deletions x/authz/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"bytes"
"fmt"

"cosmossdk.io/core/codec"
"cosmossdk.io/x/authz"
"cosmossdk.io/x/authz/keeper"

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

Expand All @@ -18,13 +18,21 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], keeper.GrantKey):
var grantA, grantB authz.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)
case bytes.Equal(kvA.Key[:1], keeper.GrantQueuePrefix):
var grantA, grantB authz.GrantQueueItem
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 authz key %X", kvA.Key))
Expand Down
3 changes: 1 addition & 2 deletions x/gov/migrations/v5/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"

"cosmossdk.io/collections"
"cosmossdk.io/core/codec"
corestoretypes "cosmossdk.io/core/store"
govv1 "cosmossdk.io/x/gov/types/v1"

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

var (
Expand Down
8 changes: 6 additions & 2 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"google.golang.org/grpc"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/core/registry"
govclient "cosmossdk.io/x/gov/client"
"cosmossdk.io/x/gov/client/cli"
Expand All @@ -20,7 +21,6 @@ import (
"cosmossdk.io/x/gov/types/v1beta1"

"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"
Expand Down Expand Up @@ -157,7 +157,11 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {

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

// ValidateGenesis performs genesis state validation for the gov module.
Expand Down

0 comments on commit 348975e

Please sign in to comment.