2

I have a struct like this:

    struct Game {

       string gameID;
       string[2] teams;
       string winningTeam;
       string losingTeam;

       mapping(string => uint) totalWeiBet;

       mapping(string => Bet[]) bets;
       mapping(string => Token[]) tokens;
       mapping(string => mapping(address => bool)) wasSuchTokenBet;


       bool isLocked;
       bool isFinalized;
   }

and a state mapping which holds all active Games:

   mapping(string => Game) activeGames;

When I'm done with the game and I no longer need it (because it is finalized) - I am wondering - how much of the struct do I want to delete? Do I simply delete the struct out of active games mapping? Or should I try to clear all the mappings inside of the struct first? Why would I clear them? What if I don't and I simply delete the whole struct? Does delete cost me additional gas in any case, or it's the other way around - it never costs anything so there is no disadventage of deleting?

Thanks for help again! I love the community here!

1

If you change the struct you have to pay gas.

In my opinion this is a better way to manage structs. You just push the new struct in an array and leave the old ones that you dont need anymore.

Game[] public games;

struct Game{

   string gameID;
   string[2] teams;
   string winningTeam;
   string losingTeam;

   mapping(string => uint) totalWeiBet;

   mapping(string => Bet[]) bets;
   mapping(string => Token[]) tokens;
   mapping(string => mapping(address => bool)) wasSuchTokenBet;


   bool isLocked;
   bool isFinalized;

}

  • Not possible in my case because I need to map games with corresponding ID and doesn't anwser my questions. Thanks for help though. – lemme Oct 10 '18 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.