3

code like this: struct Voter { bool voted; uint vote; uint votetime; bytes32 remark; } mapping(address => Voter) public voters;

I want to judge like this: if(voters[msg.sender]) { do something… }

6

The void key values in a mapping are set virtualy to 0

for example if there is no voter with the adddress 0X01 if we request the key value corresponding to this address we will get :

bool voted: false
uint256 vote: 0
uint256 votetime: 0
bytes32 remark: 0x0000000000000000000000000000000000000000000000000000000000000000

so depending on how the voting function is implemented you could check using one of this structure's parameter if it =0 e.g (voters[msg.sender].voted==0) or adding an address or an ID parameter to your structure. the idea is to have a parameter which become non-null(!=0) if user is registered or if he votes.

2
  • 1
    Also, in case you didn't realize it, you can check if remark is empty by simply comparing it to 0x0 since it and 0x0000000000000000000000000000000000000000000000000000000000000000 are the same value.
    – cryptihkal
    Dec 21 '16 at 20:26
  • how this resolve the question? i was explaining the null concept no more. remark could be 0x0 even if the voter exists do you relize that? this depends on how the contract works. my answer was to use some of this parameter as a proof of vote.
    – Badr Bellaj
    Dec 21 '16 at 20:34

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.