Skip to content

Commit

Permalink
Merge pull request #138 from DecentralCardGame/135-starter-cards
Browse files Browse the repository at this point in the history
135 starter cards
  • Loading branch information
lxgr-linux authored Sep 29, 2023
2 parents b7c3a67 + 11cdbfc commit 9244888
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 169 deletions.
8 changes: 8 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33136,6 +33136,8 @@ paths:
type: boolean
hash:
type: string
starterCard:
type: boolean
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -33330,6 +33332,10 @@ paths:
in: query
required: false
type: string
- name: onlyStarterCard
in: query
required: false
type: boolean
tags:
- Query
/DecentralCardGame/cardchain/cardchain/q_collection/{collectionId}:
Expand Down Expand Up @@ -68860,6 +68866,8 @@ definitions:
type: boolean
hash:
type: string
starterCard:
type: boolean
DecentralCardGame.cardchain.cardchain.OutpCollection:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions proto/cardchain/cardchain/card.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message Card {
uint64 inappropriateVotes = 12;
int64 nerflevel = 13;
bool balanceAnchor = 15;
bool starterCard = 16;
}

message OutpCard {
Expand All @@ -42,6 +43,7 @@ message OutpCard {
int64 nerflevel = 13;
bool balanceAnchor = 15;
string hash = 16;
bool starterCard = 17;
}

enum Status {
Expand Down
1 change: 1 addition & 0 deletions proto/cardchain/cardchain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ message QueryQCardsRequest {
string nameContains = 6;
string keywordsContains = 7;
string notesContains = 8;
bool onlyStarterCard = 9;
}

message QueryQCardsResponse {
Expand Down
12 changes: 12 additions & 0 deletions x/cardchain/keeper/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ func (k Keeper) SetCardToTrial(ctx sdk.Context, cardId uint64, votePool sdk.Coin
k.Cards.Set(ctx, cardId, card)
k.SetLastCardModifiedNow(ctx)
}

func (k Keeper) GetAllStarterCards(ctx sdk.Context) (cards []uint64) {
iter := k.Cards.GetItemIterator(ctx)

for ; iter.Valid(); iter.Next() {
idx, gottenCard := iter.Value()
if gottenCard.StarterCard {
cards = append(cards, idx)
}
}
return
}
6 changes: 6 additions & 0 deletions x/cardchain/keeper/grpc_query_q_cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ func (k Keeper) QCards(goCtx context.Context, req *types.QueryQCardsRequest) (*t
for ; iterator.Valid(); iterator.Next() {
idx, gottenCard := iterator.Value()

// filter for starterCards
if req.OnlyStarterCard && !gottenCard.StarterCard {
continue
}

// first skip all cards with irrelevant status
if gottenCard.Status == types.Status_none || gottenCard.Status == types.Status_scheme {
continue
}

// then check if a status constrain was given and skip the card if it has the wrong status
if req.Status != types.QueryQCardsRequest_none {
if !slices.Contains(states, gottenCard.Status) {
Expand Down
7 changes: 7 additions & 0 deletions x/cardchain/keeper/msg_server_create_sell_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

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

sdkerrors "cosmossdk.io/errors"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
Expand All @@ -16,6 +17,12 @@ func (k msgServer) CreateSellOffer(goCtx context.Context, msg *types.MsgCreateSe
return nil, sdkerrors.Wrap(types.ErrUserDoesNotExist, err.Error())
}

// Check if card is startercard
card := k.Cards.Get(ctx, msg.Card)
if card.StarterCard {
return nil, sdkerrors.Wrap(errors.ErrUnauthorized, "Card is startercard and therefore not sellable")
}

newCards, err := PopItemFromArr(msg.Card, creator.Cards)
if err != nil {
return nil, sdkerrors.Wrapf(err, "User does not posses Card: %d", msg.Card)
Expand Down
1 change: 1 addition & 0 deletions x/cardchain/keeper/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (k Keeper) InitUser(ctx sdk.Context, address sdk.AccAddress, alias string)
}
newUser := types.NewUser()
newUser.Alias = alias
newUser.Cards = k.GetAllStarterCards(ctx)
err := k.MintCoinsToAddr(ctx, address, sdk.Coins{sdk.NewInt64Coin("ucredits", 10000000000)})
if err != nil {
return err
Expand Down
165 changes: 126 additions & 39 deletions x/cardchain/types/card.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9244888

Please sign in to comment.