From e00a3c5b9ebf5dd6a3f8ec876e6d7de95e3a7fd8 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Fri, 6 Oct 2023 14:59:45 +0200 Subject: [PATCH] Fixed cli tx_set_card_rarity --- scripts/migrate_with_data.py | 4 ++-- x/cardchain/client/cli/tx_set_card_rarity.go | 16 ++++++---------- .../keeper/msg_server_open_booster_pack.go | 3 +++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/migrate_with_data.py b/scripts/migrate_with_data.py index 2d9681aa..e633cdcd 100755 --- a/scripts/migrate_with_data.py +++ b/scripts/migrate_with_data.py @@ -40,8 +40,8 @@ # delete all sets # TODO REMOVE THIS PART ONCE EVERYTHING IS FINE -print(old_dict["app_state"]["cardchain"]["sets"]) -old_dict["app_state"]["cardchain"]["sets"] = [] +#print(old_dict["app_state"]["cardchain"]["sets"]) +#old_dict["app_state"]["cardchain"]["sets"] = [] params = new_dict["app_state"]["cardchain"]["params"] diff --git a/x/cardchain/client/cli/tx_set_card_rarity.go b/x/cardchain/client/cli/tx_set_card_rarity.go index 519cdc08..b39eee7e 100644 --- a/x/cardchain/client/cli/tx_set_card_rarity.go +++ b/x/cardchain/client/cli/tx_set_card_rarity.go @@ -1,7 +1,7 @@ package cli import ( - "github.com/DecentralCardGame/cardobject/cardobject" + "fmt" "strconv" "github.com/DecentralCardGame/Cardchain/x/cardchain/types" @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cast" "github.com/spf13/cobra" + "golang.org/x/exp/maps" ) var _ = strconv.Itoa(0) @@ -28,17 +29,12 @@ func CmdSetCardRarity() *cobra.Command { if err != nil { return err } - rar, err := strconv.Atoi(args[2]) - if err != nil { - return err + rar, found := types.CardRarity_value[args[2]] + if (!found) { + return fmt.Errorf("Rarity has to be in %s", maps.Keys(types.CardRarity_value)) } - argRarity := types.CardRarity(rar) - rarity := cardobject.Rarity(argRarity) - err = rarity.ValidateType(cardobject.Card{}) - if err != nil { - return err - } + argRarity := types.CardRarity(rar) clientCtx, err := client.GetClientTxContext(cmd) if err != nil { diff --git a/x/cardchain/keeper/msg_server_open_booster_pack.go b/x/cardchain/keeper/msg_server_open_booster_pack.go index b294cfba..547a071c 100644 --- a/x/cardchain/keeper/msg_server_open_booster_pack.go +++ b/x/cardchain/keeper/msg_server_open_booster_pack.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "context" "math/rand" @@ -41,6 +42,7 @@ func (k msgServer) OpenBoosterPack(goCtx context.Context, msg *types.MsgOpenBoos cleanedRatios[idx] = ratio } } + fmt.Printf("%s", rarityNums) for idx, num := range creator.BoosterPacks[msg.BoosterPackId].RaritiesPerPack { for i := 0; i < int(num); i++ { @@ -74,6 +76,7 @@ func (k msgServer) OpenBoosterPack(goCtx context.Context, msg *types.MsgOpenBoos func (k Keeper) getCardRaritiesInSet(ctx sdk.Context, set *types.Set) (rarityNums [5][]uint64) { for _, cardId := range set.Cards { card := k.Cards.Get(ctx, cardId) + fmt.Println(card.Rarity) rarityNums[int(card.Rarity)] = append(rarityNums[int(card.Rarity)], cardId) } return