nested stuff inside index_table Leave a comment

I’m trying to build a small hearthstone like game and I’ve finished up the front-end for the game client. I created a NoSQL mockup of the user data and now it’s time to move those to the index_table in smart contract code.

Here is how the user data template looks like in my front-end (typescript):

interface User {
  name: string,
  xp: number,
  lv: number,
  avatar: string,
  isInGame: boolean,
  selectedDeckName: string,
  redShards: number,
  blueShards: number,
  cards: {
    solid: Card[],
    liquid: Card[],
    gas: Card[],
    plasma: Card[],
    neutral: Card[]

interface Card {
   name: string,
   selectedSkinName: string,
   skins: CardSkin[]

interface CardSkin {
   name: string,
   owned: number

so I implemented the index_table like this in smart contract:

struct [[eosio::table]] user {
  name username;
  int xp;
  int lv;
  string avatar;
  bool isInGame;
  string selectedDeckName;
  int redShards;
  int blueShards;
  uint64_t primary_key() const {return username.value;}

Apart from cards there is also a decks object which also has nested arrays of objects inside that keeps track of decks users create but I didn’t include them here for simplicity, since same logic applies to both card and deck objects.

And i managed to insert some data with cleos and fetch it with the eosjs lib to my frontend. But now I’m stuck with the cards object, which has 5 arrays nested inside and all those 5 arrays should be arrays of Card objects, and it nests pretty deep. I’m so used to MongoDB and noSQL but this index_table feels like SQL to me (it is a table indeed), so maybe this is why I’m struggling.

How would you guys approach this? The only thing that comes to mind is 60 tables (12 cards for each class) but doesn’t feel like the right solution to me.

I’m not sure whether this question has any sense but I had nowhere else to turn. Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *