diff --git a/go.mod b/go.mod index 6e0f5864..e17720a9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3f4778cd..008b8085 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/x/cardchain/genesis.go b/x/cardchain/genesis.go index 0f98d048..c59bdded 100644 --- a/x/cardchain/genesis.go +++ b/x/cardchain/genesis.go @@ -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" ) @@ -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) diff --git a/x/cardchain/keeper/grpc_query_q_cards.go b/x/cardchain/keeper/grpc_query_q_cards.go index 67a587d6..16cd2680 100644 --- a/x/cardchain/keeper/grpc_query_q_cards.go +++ b/x/cardchain/keeper/grpc_query_q_cards.go @@ -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 {