1

I have a read function to check whether someone should go and use the write MakeEligible function. Here is the code:

function ShouldIMakeMyselfEligible(address) public view returns (bool) {
    if (_RestrictedFromDividend[address(msg.sender)]) {
        if (now >= (ClaimTime[address(msg.sender)] + 10 minutes)) {
            return true;
        } else {
            return false;
        }
     } else {
        return false;
    }
}

I have tested that yes, the address is _RestrictedFromDividend, and also if they claim before 10 minutes has passed in the following function:

function MakeEligible(address) public {
    if (now >= (ClaimTime[address(msg.sender)] + 10 minutes)) {
        _RestrictedFromDividend[address(msg.sender)] = false;
    } else {
        _RestrictedFromDividend[address(msg.sender)] = true;
    }
}

Nothing will happen and they will remain _RestrictedFromDividend, which is what I want to happen. Once 10 minutes has passed, even though ShouldIMakeMyselfEligible will return false, using the MakeEligible command will successfully make the _RestrictedFromDividend go away. So I know that the ClaimTime is updating and calculating correctly but in the first function something has gone wrong. Can someone help me?

1

In ShouldIMakeMyselfEligible you are performing checks against msg.sender, which is used to access the calling address in a transaction. However, this function is marked as view and so is accessed via a call rather than a transaction. msg.sender likely does not contain the data you expect it to.

You specify that an address should be given as an input to ShouldIMakeMyselfEligible, however you do not name this variable. My guess is that you are unclear on the use of function inputs and msg.sender, and your intention was that the user supplies their address when calling ShouldIMakeMyselfEligible. In that case, you should instead give a name to the inputted address and perform the checks against this named variable:

function ShouldIMakeMyselfEligible(address _addr) public view returns (bool) {
    if (
        _RestrictedFromDividend[_addr] &&
        now >= (ClaimTime[_addr] + 10 minutes)
    ) {
        return true;
    } else {
        return false;
    }
}

Your second function is accessed via a transaction and so msg.sender is being used correctly. However, there is no need to include an address in the function inputs. And you do not need to wrap msg.sender in address() - it already is an address.

function MakeEligible() public {
    if (now >= (ClaimTime[msg.sender] + 10 minutes)) {
        _RestrictedFromDividend[msg.sender] = false;
    } else {
        _RestrictedFromDividend[msg.sender] = true;
    }
}

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.