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/group,x/nft,x/mint): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec #23293

Closed
wants to merge 3 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/group/internal/orm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
7 changes: 4 additions & 3 deletions x/group/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions x/group/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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"
"cosmossdk.io/x/group/keeper"
"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"
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 31 additions & 11 deletions x/group/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/group"
"cosmossdk.io/x/group/keeper"

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

Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

"cosmossdk.io/collections"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/core/registry"
"cosmossdk.io/schema"
"cosmossdk.io/x/mint/keeper"
"cosmossdk.io/x/mint/simulation"
"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"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions x/nft/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"google.golang.org/grpc"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/codec"
"cosmossdk.io/core/registry"
"cosmossdk.io/errors"
"cosmossdk.io/x/nft"
"cosmossdk.io/x/nft/keeper"
"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"
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions x/nft/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/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"
)
Expand All @@ -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)
Expand Down
Loading