The share_pension() method

As you saw, in the previous function we called share_pension() to share the eliminated player’s deposit. Here’s its implementation:

function share_pension(address user) internal returns (bool) {
uint256 remainingPlayers = remaining_players();
for(uint256 i = 0; i < active_players.length; i++){
if (active_players[i].Paddress != 0x00)
Tpension[active_players[i].Paddress] = Tpension[user] / remaining_players;
}
return true;
}

function remaining_players() public view returns (uint256) {
return (active_players.length-eliminated_players.length);
}
}

We declare this function internal as it’s intended to be used only within the contract scope. As we can see, share_pension() shares the eliminated players’ balances between the remaining active players. This function has to allocate the Tpension[user]/remaining_players quotient to each active player. However, we are facing a problem here! Have you spotted it?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset