Skip to content

Commit

Permalink
feat(#242): CardArtworkAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Dec 17, 2024
1 parent aa9b778 commit b6ad90d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 303 deletions.
29 changes: 27 additions & 2 deletions x/cardchain/keeper/msg_server_card_artwork_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,40 @@ package keeper
import (
"context"

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

func (k msgServer) CardArtworkAdd(goCtx context.Context, msg *types.MsgCardArtworkAdd) (*types.MsgCardArtworkAddResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx
card := k.Cards.Get(ctx, msg.CardId)
image := k.Images.Get(ctx, card.ImageId)

councilEnabled, err := k.FeatureFlagModuleInstance.Get(ctx, string(types.FeatureFlagName_Council))
if err != nil {
return nil, err
}

if councilEnabled && card.Status != types.Status_prototype && card.Status != types.Status_scheme {
return nil, sdkerrors.Wrap(types.ErrInvalidCardStatus, "Card has to be a prototype to be changeable")
}

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

card.FullArt = msg.FullArt
image.Image = msg.Image

if card.Status == types.Status_suspended {
card.Status = types.Status_permanent
}

k.Cards.Set(ctx, msg.CardId, card)
k.Images.Set(ctx, card.ImageId, image)

return &types.MsgCardArtworkAddResponse{}, nil
}
6 changes: 4 additions & 2 deletions x/cardchain/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

// x/cardchain module sentinel errors
var (
ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message")
ErrSample = sdkerrors.Register(ModuleName, 1101, "sample error")
ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message")
ErrInvalidCardStatus = sdkerrors.Register(ModuleName, 13, "Invalid card-status")
ErrImageSizeExceeded = sdkerrors.Register(ModuleName, 17, "Image too big! Max size is 500kb")
ErrInvalidData = sdkerrors.Register(ModuleName, 27, "Invalid data in transaction")
)
9 changes: 9 additions & 0 deletions x/cardchain/types/message_card_artwork_add.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package types

import (
fmt "fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const ArtworkMaxSize = 500000

var _ sdk.Msg = &MsgCardArtworkAdd{}

func NewMsgCardArtworkAdd(creator string, cardId uint64, image []byte, fullArt bool) *MsgCardArtworkAdd {
Expand All @@ -22,5 +26,10 @@ func (msg *MsgCardArtworkAdd) ValidateBasic() error {
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}

if len(msg.Image) > ArtworkMaxSize {
return errorsmod.Wrap(ErrImageSizeExceeded, fmt.Sprint(len(msg.Image)))
}

return nil
}
299 changes: 0 additions & 299 deletions x/cardchain/types/num.pb.go

This file was deleted.

0 comments on commit b6ad90d

Please sign in to comment.