Skip to content

Commit

Permalink
Fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Aug 21, 2023
1 parent 17b328e commit 5068353
Show file tree
Hide file tree
Showing 134 changed files with 382 additions and 291 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/DecentralCardGame/Cardchain
go 1.20

require (
cosmossdk.io/errors v1.0.0-beta.7
github.com/DecentralCardGame/cardobject v0.5.0
github.com/cosmos/cosmos-sdk v0.46.15
github.com/cosmos/ibc-go/v6 v6.1.0
Expand All @@ -29,7 +30,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-rc.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down
5 changes: 3 additions & 2 deletions x/cardchain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cardchain
import (
"fmt"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/keeper"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
)

// NewHandler ...
Expand Down Expand Up @@ -134,7 +135,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
// this line is used by starport scaffolding # 1
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, errMsg)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/cardchain/keeper/coin.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package keeper

import (
sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"math/big"
)

Expand Down
2 changes: 1 addition & 1 deletion x/cardchain/keeper/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package keeper
import (
"errors"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
"github.com/DecentralCardGame/cardobject/cardobject"
"github.com/DecentralCardGame/cardobject/keywords"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// CollectCollectionFee Collects a fee from a user
Expand Down
10 changes: 6 additions & 4 deletions x/cardchain/keeper/grpc_query_q_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"strconv"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -23,12 +25,12 @@ func (k Keeper) QCard(goCtx context.Context, req *types.QueryQCardRequest) (*typ
// Start of query code
cardId, err := strconv.ParseUint(req.CardId, 10, 64)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not parse cardId")
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, "could not parse cardId")
}

card := k.Cards.Get(ctx, cardId)
if card == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "cardId does not represent a card")
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, "cardId does not represent a card")
}

image := k.Images.Get(ctx, card.ImageId)
Expand All @@ -50,7 +52,7 @@ func (k Keeper) QCard(goCtx context.Context, req *types.QueryQCardRequest) (*typ
UnderpoweredVotes: card.UnderpoweredVotes,
InappropriateVotes: card.InappropriateVotes,
Nerflevel: card.Nerflevel,
BalanceAnchor: card.BalanceAnchor,
BalanceAnchor: card.BalanceAnchor,
Hash: hash,
}

Expand Down
7 changes: 4 additions & 3 deletions x/cardchain/keeper/grpc_query_q_card_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"github.com/cosmos/cosmos-sdk/types/errors"
"strconv"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -23,12 +24,12 @@ func (k Keeper) QCardContent(goCtx context.Context, req *types.QueryQCardContent

cardId, err := strconv.ParseUint(req.CardId, 10, 64)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not parse cardId")
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, "could not parse cardId")
}

card := k.Cards.Get(ctx, cardId)
if &card == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "cardId does not represent a card")
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, "cardId does not represent a card")
}

image := k.Images.Get(ctx, card.ImageId)
Expand Down
7 changes: 4 additions & 3 deletions x/cardchain/keeper/grpc_query_q_cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/json"
"sort"
"strings"
"strconv"
"strings"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
"github.com/DecentralCardGame/cardobject/cardobject"
"github.com/DecentralCardGame/cardobject/keywords"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
"golang.org/x/exp/slices"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -135,7 +136,7 @@ func (k Keeper) QCards(goCtx context.Context, req *types.QueryQCardsRequest) (*t
if req.NameContains != "" || req.CardType != "" || req.SortBy != "" || req.Classes != "" || req.KeywordsContains != "" {
cardobj, err := keywords.Unmarshal(gottenCard.Content)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()+"cardid="+strconv.FormatUint(idx, 10))
return nil, sdkerrors.Wrap(errors.ErrJSONMarshal, err.Error()+"cardid="+strconv.FormatUint(idx, 10))
}

if cardobj.Action != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/cardchain/keeper/grpc_query_q_sell_offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package keeper
import (
"context"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down
2 changes: 1 addition & 1 deletion x/cardchain/keeper/grpc_query_q_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package keeper
import (
"context"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down
5 changes: 3 additions & 2 deletions x/cardchain/keeper/grpc_query_q_votable_cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package keeper
import (
"context"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand All @@ -19,7 +20,7 @@ func (k Keeper) QVotableCards(goCtx context.Context, req *types.QueryQVotableCar

address, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not parse user address")
return nil, sdkerrors.Wrap(errors.ErrUnknownRequest, "could not parse user address")
}

unreg := true
Expand Down
14 changes: 7 additions & 7 deletions x/cardchain/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/types/errors"
"sort"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
func (k Keeper) TransferSchemeToCard(ctx sdk.Context, cardId uint64, user *User) (err error) {
user.OwnedCardSchemes, err = PopItemFromArr(cardId, user.OwnedCardSchemes)
if err != nil {
return sdkerrors.ErrUnauthorized
return errors.ErrUnauthorized
}

user.OwnedPrototypes = append(user.OwnedPrototypes, cardId)
Expand Down Expand Up @@ -118,10 +118,10 @@ func (k Keeper) GetLastVotingResults(ctx sdk.Context) (results types.VotingResul
// NerfBuffCards Nerfes or buffs certain cards
// TODO maybe the whole auto balancing stuff should be moved into its own file
func (k Keeper) NerfBuffCards(ctx sdk.Context, cardIds []uint64, buff bool) {
if len(cardIds) > 0 {
k.SetLastCardModifiedNow(ctx)
if len(cardIds) > 0 {
k.SetLastCardModifiedNow(ctx)
}

for _, val := range cardIds {
buffCard := k.Cards.Get(ctx, val)

Expand Down Expand Up @@ -221,8 +221,8 @@ func (k Keeper) UpdateBanStatus(ctx sdk.Context, newBannedIds []uint64) {
k.Cards.Set(ctx, id, banCard)
}

if len(newBannedIds) > 0 {
k.SetLastCardModifiedNow(ctx)
if len(newBannedIds) > 0 {
k.SetLastCardModifiedNow(ctx)
}
}

Expand Down
6 changes: 4 additions & 2 deletions x/cardchain/keeper/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package keeper

import (
"fmt"
"github.com/cosmos/cosmos-sdk/types/errors"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -78,7 +80,7 @@ func (k Keeper) DistributeCoins(ctx sdk.Context, match *types.Match, outcome typ
if !amounts[idx].IsZero() {
err := k.MintCoinsToAddr(ctx, address, sdk.Coins{amounts[idx]})
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, err.Error())
return sdkerrors.Wrap(errors.ErrInsufficientFunds, err.Error())
}
k.SubPoolCredits(ctx, WinnersPoolKey, amounts[idx])

Expand Down
5 changes: 3 additions & 2 deletions x/cardchain/keeper/msg_server_add_artwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package keeper
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/types/errors"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

func (k msgServer) AddArtwork(goCtx context.Context, msg *types.MsgAddArtwork) (*types.MsgAddArtworkResponse, error) {
Expand All @@ -21,7 +22,7 @@ func (k msgServer) AddArtwork(goCtx context.Context, msg *types.MsgAddArtwork) (
//}

if card.Artist != msg.Creator {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Incorrect Artist")
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Incorrect Artist")
}

if len(msg.Image) > 500000 {
Expand Down
7 changes: 4 additions & 3 deletions x/cardchain/keeper/msg_server_add_artwork_to_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
)

func (k msgServer) AddArtworkToCollection(goCtx context.Context, msg *types.MsgAddArtworkToCollection) (*types.MsgAddArtworkToCollectionResponse, error) {
Expand All @@ -16,7 +17,7 @@ func (k msgServer) AddArtworkToCollection(goCtx context.Context, msg *types.MsgA
image := k.Images.Get(ctx, collection.ArtworkId)

if collection.Artist != msg.Creator {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Incorrect Artist")
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Incorrect Artist")
}
if collection.Status != types.CStatus_design {
return nil, types.ErrCollectionNotInDesign
Expand All @@ -28,7 +29,7 @@ func (k msgServer) AddArtworkToCollection(goCtx context.Context, msg *types.MsgA

err := k.CollectCollectionConributionFee(ctx, msg.Creator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, err.Error())
return nil, sdkerrors.Wrap(errors.ErrInsufficientFunds, err.Error())
}

image.Image = msg.Image
Expand Down
9 changes: 5 additions & 4 deletions x/cardchain/keeper/msg_server_add_card_to_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package keeper
import (
"context"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
"golang.org/x/exp/slices"
)

Expand All @@ -16,7 +17,7 @@ func (k msgServer) AddCardToCollection(goCtx context.Context, msg *types.MsgAddC

collection := k.Collections.Get(ctx, msg.CollectionId)
if !slices.Contains(collection.Contributors, msg.Creator) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid contributor")
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Invalid contributor")
}
if collection.Status != types.CStatus_design {
return nil, types.ErrCollectionNotInDesign
Expand All @@ -36,7 +37,7 @@ func (k msgServer) AddCardToCollection(goCtx context.Context, msg *types.MsgAddC
}

if card.Owner != msg.Creator {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid creator")
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Invalid creator")
}

if len(collection.Cards) >= collectionSize {
Expand All @@ -49,7 +50,7 @@ func (k msgServer) AddCardToCollection(goCtx context.Context, msg *types.MsgAddC

err := k.CollectCollectionConributionFee(ctx, msg.Creator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, err.Error())
return nil, sdkerrors.Wrap(errors.ErrInsufficientFunds, err.Error())
}

collection.Cards = append(collection.Cards, msg.CardId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package keeper
import (
"context"

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/errors"
"golang.org/x/exp/slices"
)

Expand All @@ -14,7 +15,7 @@ func (k msgServer) AddContributorToCollection(goCtx context.Context, msg *types.

collection := k.Collections.Get(ctx, msg.CollectionId)
if msg.Creator != collection.Contributors[0] {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid creator")
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Invalid creator")
}
if collection.Status != types.CStatus_design {
return nil, types.ErrCollectionNotInDesign
Expand All @@ -26,7 +27,7 @@ func (k msgServer) AddContributorToCollection(goCtx context.Context, msg *types.

err := k.CollectCollectionConributionFee(ctx, msg.Creator)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, err.Error())
return nil, sdkerrors.Wrap(errors.ErrInsufficientFunds, err.Error())
}

collection.Contributors = append(collection.Contributors, msg.User)
Expand Down
Loading

0 comments on commit 5068353

Please sign in to comment.