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…
}
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityThe 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.
0x0
since it and 0x0000000000000000000000000000000000000000000000000000000000000000
are the same value.
Dec 21, 2016 at 20:26