4

I want to check if the Address sender is already in Address[]. If true, then do not allow this address to make the payment.

Contract Hello {
  address[] internal Pool;

  function () public payable {
  require(msg.value * 10 == 1 ether);

  if (msg.sender already exist in address[]){
    revert();
    Rejected();

  } else {
    Pool.push(msg.sender);
  }
 }
}

Thank you!

2

As i feel easy way is to keep a mapping that would store Boolean value true for already in addresses.

Contract Hello {
  address[] internal Pool;
  mapping (address => boolean) private oldUsers;


  function () public payable {
  require(msg.value * 10 == 1 ether);

  //check for old users
  if (oldUsers[msg.sender]){
    revert();
    Rejected();

  } else {
    Pool.push(msg.sender);
    // enter as an old user
    oldUsers[msg.sender] = true;
  }
 }
}
| improve this answer | |

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.