0

I am trying to push data to an address array within a struct array. There are no errors, however, when I check the storage of the array in my contract in Ganache, it remains empty. Is there something wrong with my code? Or is it not meant to display in Ganache? And if the data doesn't display in Ganache, does that mean it isn't being stored anywhere?

My code is provided below. I am trying to push data to the address array challengers in struct array challenges through function acceptChallenge.

pragma solidity >=0.5.0 <0.6.0;

contract GameChanger {

    uint ChallengeCount = 0;

    struct Challenge {
        string name;
        address host;
        string description;
        uint starttime;
        uint timelimit;
        uint reward;
        uint challengercount;
        address[] challengers;
    }

    Challenge[] public challenges;

    function createChallenge(string memory name, string memory description, 
        uint timelimit, uint reward) public {

        ChallengeCount++;
        address host = msg.sender;
        uint starttime = now;
        uint challengercount = 0;
        challenges.push(Challenge(name, host, description, starttime,                         
        timelimit, reward, challengercount, new address[](0)));
    }

    function acceptChallenge(uint ChallengeCount) public {

        if (now <= ((challenges[ChallengeCount].starttime)  + 24)) {
            challenges[ChallengeCount].challengers.push(msg.sender);
            challenges[ChallengeCount].challengercount++;
            uint id = challenges[ChallengeCount].challengercount;
            registration[id] = msg.sender;
        }
    }
}
1
  • Question has been rolled back.
    – eth
    May 11 '20 at 5:24
1

Well, in function acceptChallenge, everything is inside an if clause.

The simple conclusion is that the condition in the if statement is always false.

Looking at it, I suspect that you're expecting those 24 seconds to elapse "on their own".

This is not the case in Ganache, since there are no other participants but yourself.

So as long as you don't submit any transactions, time stands still.

Luckily for you, the Ganache EVM has a non-standard interface.

Amongst other things, this interface allows you to move forward in time.

For example, in order to jump 24 seconds forward, you can do:

web3.currentProvider.send({method: "evm_increaseTime", params: [24]});

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.