Skip to content

Commit

Permalink
Merge branch '234-update-cardobject-to-v052' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jul 3, 2024
2 parents f96d93f + 0fcfb7f commit c546068
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
cosmossdk.io/errors v1.0.0-beta.7
github.com/DecentralCardGame/cardobject v0.5.1
github.com/DecentralCardGame/cardobject v0.5.3
github.com/cosmos/cosmos-sdk v0.46.15
github.com/cosmos/ibc-go/v6 v6.1.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/DecentralCardGame/cardobject v0.5.1 h1:bp91ZL08DwJj6M87i7cDzNB2grYRY/TzbvxGp3bESVw=
github.com/DecentralCardGame/cardobject v0.5.1/go.mod h1:waAoRvDCDVTBlPjEroIIfXpX2PQnJvgUssRN4Ji4VFM=
github.com/DecentralCardGame/cardobject v0.5.3 h1:Ama1q0ij7iFV6ZcOtaH3n4DbmmPojlC6QR7G+Md5sPE=
github.com/DecentralCardGame/cardobject v0.5.3/go.mod h1:waAoRvDCDVTBlPjEroIIfXpX2PQnJvgUssRN4Ji4VFM=
github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
github.com/Djarvur/go-err113 v0.1.0/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
Expand Down
26 changes: 23 additions & 3 deletions x/cardchain/genesis.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cardchain

import (
"encoding/json"
"fmt"

"github.com/DecentralCardGame/Cardchain/x/cardchain/keeper"
"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
"github.com/DecentralCardGame/cardobject/cardobject"
"github.com/DecentralCardGame/cardobject/keywords"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -49,9 +51,27 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
}
k.Logger(ctx).Info("reading cards with id:")
for currId, record := range genState.CardRecords {
_, err := keywords.Unmarshal(record.Content)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("%d :\n\t%s\n\t%s\n-----", currId, err.Error(), record.Content))
if len(record.Content) != 0 {
_, err := keywords.Unmarshal(record.Content)

if err != nil {
k.Logger(ctx).Info(fmt.Sprintf("Failed to read %d :\n\t%s\n\t%s\n-----", currId, err.Error(), record.Content))
var card keywords.Card
json.Unmarshal(record.Content, &card)

switch card.GetType() {
case cardobject.ENTITYTYPE:
card.Entity.Abilities.Clear()
case cardobject.PLACETYPE:
card.Place.Abilities.Clear()
case cardobject.HEADQUARTERTYPE:
card.Headquarter.Abilities.Clear()
case cardobject.ACTIONTYPE:
card.Action.Effects.Clear()
}
jsonBytes, _ := json.Marshal(card)
record.Content = jsonBytes
}
}

k.Cards.Set(ctx, uint64(currId), record)
Expand Down
2 changes: 1 addition & 1 deletion x/cardchain/keeper/grpc_query_q_cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (k Keeper) QCards(goCtx context.Context, req *types.QueryQCardsRequest) (*t
if req.NameContains != "" || len(req.CardTypes) != 0 || req.SortBy != "" || len(req.Classes) != 0 || req.KeywordsContains != "" {
cardobj, err := keywords.Unmarshal(gottenCard.Content)
if err != nil {
return nil, sdkerrors.Wrap(errors.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

0 comments on commit c546068

Please sign in to comment.