1

Here is the function in question :

function WithdrawDividend(address, uint256 value) public {

  require(value <= _balances[msg.sender]);

  if (!RestrictedFromDividend[msg.sender]) {

    _SavedDividend[msg.sender] = 
    _balances[address(this)].mul(value).div(100000000);  
    uint256 DividendsToBurn = _SavedDividend[msg.sender].mul(10).div(10000);
    uint256 DividendstoDividend = _SavedDividend[msg.sender].sub(DividendsToBurn);

    _balances[address(this)] = _balances[address(this)].sub(DividendstoDividend).sub(DividendsToBurn);
    _balances[msg.sender] = _balances[msg.sender].add(DividendstoDividend);
    _balances[address(0)] = _balances[address(0)].add(DividendsToBurn);

    emit Transfer(address(this), msg.sender, DividendstoDividend);
    emit Transfer(address(this), address(0), DividendsToBurn);

    _SavedDividend[msg.sender] = 0;

    RestrictedFromDividend[msg.sender] = true;

    ClaimTime[msg.sender] = now;
  }
}

When I use this function here to check whether or not a person is RestrictedFromDividend or not :

function AmIRestrictedFromTheDividend(address) public view returns (bool) {

  if(!RestrictedFromDividend[msg.sender]){

    return false;

  } else {

    return true;

  }
}

I get 'false' returned everytime, even after immediately using the WithdrawDividend function.

RestrictedFromDividend is removed using the following function, if that helps:

function MakeEligible(address) public {

  if (now >= ClaimTime[msg.sender] + 30 minutes){

    RestrictedFromDividend[msg.sender] = false;

  } else {

    RestrictedFromDividend[msg.sender] = true;

  }
}
2

Simple Mistake, Problem is in this function,

function AmIRestrictedFromTheDividend(address) public view returns (bool) {
  if(!RestrictedFromDividend[msg.sender]){
    return false;
  } else {
    return true;
  }
}

You are taking an address as an argument but passing msg.sender to mapping. That's why it shows always incorrect info.

So you need to chage that function like this,

function AmIRestrictedFromTheDividend(address) public view returns (bool) {
  if(!RestrictedFromDividend[address]){
    return false;
  } else {
    return true;
  }
}

I hope this will solve your problem.

2
  • When I change it to [address] instead of [msg.sender] I get an error: Type type(address) is not implicitly convertible to expected type address. – manilpwn Jul 20 '19 at 2:39
  • Write this line instead of that, AmIRestrictedFromTheDividend(address _addr) .And same for below line. – Meet Siraja Jul 21 '19 at 5:44
2

The other answer should be accepted as correct, but just to simplify the code a bit...

function AmIRestrictedFromTheDividend(address) public view returns (bool) {
    return RestrictedFromDividend[address];
}

Edit:

As per @goodvibration's comment, the above won't even compile. The following will:

function AmIRestrictedFromTheDividend(address foo) public view returns (bool) {
    return RestrictedFromDividend[foo];
}
7
  • address is a reserved keyword, and on top of that, the name of the input argument (which should be used) is not even present in the function declaration. Same goes for the other answer, which you have pointed to. – goodvibration Jul 22 '19 at 5:30
  • Ha, good point :-) So I think the code in the question is actually correct, as anonymous parameters - without the parameter name - are fine. I doubt that was the OP's intent, but it should have been working as he/she expected, assuming that the function is only ever checking for the caller of the contract (i.e. msg.sender). The code in the other answer - which I blindly and incorrectly copied - is just wrong :-) – Richard Horrocks Jul 22 '19 at 9:34
  • Yeah okay, just saw someone called this out in one their other (near identical) questions... – Richard Horrocks Jul 22 '19 at 9:36
  • Yeah well this dude posted around 20 questions on the exact same piece of code during the last few days. I've recognized that by the RestrictedFromDividend which appears in each one of them. – goodvibration Jul 22 '19 at 9:56
  • 1
    Thanks for letting me off so easily! :-) But yes, I think you're right, this would be easy to confuse with Javascript :-) – Richard Horrocks Jul 22 '19 at 12:56

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.