-
Notifications
You must be signed in to change notification settings - Fork 22
/
Mapping.sol
28 lines (26 loc) · 988 Bytes
/
Mapping.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pragma solidity ^0.5.11;
contract RegisterParticipants {
mapping(address => bool) public MapParticipant;
address[] public ListParticipant;
mapping(address => uint) public IndexInList;
constructor() public {
ListParticipant.push(address(0)); // "use" address 0, to make tests easier
}
function Participate(bool Join) public {
MapParticipant[msg.sender]=Join;
uint i=IndexInList[msg.sender];
if (i > 0) { // Delete previous participation entry
ListParticipant[i] = ListParticipant[ListParticipant.length - 1]; // switch
IndexInList[msg.sender]=0;
IndexInList[ListParticipant[i]]=i;
ListParticipant.pop();
}
if (Join) {
ListParticipant.push(msg.sender);
IndexInList[msg.sender]=ListParticipant.length-1;
}
}
function NrOfParticipants() public view returns (uint) {
return ListParticipant.length-1;
}
}