1
function getWinners() public onlyOwner {
    require (now > endQuiztime, 'Quiz did not end ');
    require (isReveal, "You didnt reveal Questions");

    // calculate winner for each ques based on timestamp and add prize
    uint winner = 0;
    uint i;
    for(i = 0; i < 4; i++) {
        uint prev = 2**256 - 1;
        for(uint j = 1; j <= numPlayers; j++) {
            if(answers[i] == keccak256(abi.encodePacked(Players[j].choice[i],secret)) && Players[j].timestamp < prev) {
                prev = Players[j].timestamp;
                winner = j;
            }
        }
        if(winner > 0) {
            uint prize = (3 * quizFee * numPlayers) / 16;
            pendingAmount[Players[winner].account] += prize;
        }
    }
    // transfer remaining pending balance to them
    for(i = 1; i <= numPlayers; i++) {
        uint amount = pendingAmount[Players[i].account];
        emit Collected(Players[i].account, amount);

        if(amount > 0) {
            pendingAmount[Players[i].account] = 0;
            Players[i].account.payable(amount);
        }
    }
    // send contract balance to owner;
    selfdestruct(owner);
}
1

This looks like a misuse of the payable keyword.

Players[i].account.payable(amount);

We don't have enough code to know where Players[] came from, but possibly something like:

address[] payable public players;

or in a struct

struct myStruct {
  address payable account;
}

Unrelated to payable, you'll want to watch out for scalability issues because you're using unbounded for loops. Something to be aware of before you get too invested in your structure: https://blog.b9lab.com/getting-loopy-with-solidity-1d51794622ad

Hope it helps.

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.