I'm trying to allow all users to deposit tokens into my contract which I keep tracking of using a mapping mapping(address => uint256) public playerBalance;
which is fantastic. But I later need to know all the users who have made a deposit (ie. an array of all addresses). The issue I am facing is potential gas problems by storing potentially hundreds/thousands of addresses in an array.
I need to loop over all users who made a deposit and check their balances to make a distribution of tokens to them. So I wanted to create an array that adds their address when they make a deposit and removes it when they withdraw from the array but is this going to be an expensive operation to do, is there a better way?
The issue is I'd be looping through a potentially large array whenever a user makes a withdrawal, and then again (once weekly) for the distribution.