Guest User

Untitled

a guest
Mar 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. contract EmployeeStore is Restricted{
  2.  
  3. uint public employeesCount;
  4. enum authenticationStatus {Active, Inactive}
  5.  
  6. struct employee {
  7. address account;
  8. string name;
  9. string employeeID;
  10. authenticationStatus access;
  11. }
  12.  
  13. mapping (uint => employee) employees;
  14. mapping (address => uint) employeeAddressIndex;
  15. mapping (string => uint) employeeNameIndex;
  16. mapping (string => uint) employeeIDIndex;
  17.  
  18. event NewAuthenticationEvent(uint indexed id, address indexed employee, uint timestamp);
  19. event UpdateEmployeeEvent(uint indexed id, address indexed employee, uint timestamp);
  20. event RemoveAuthenticationEvent(uint indexed id, address indexed employee, uint timestamp);
  21.  
  22. function EmployeeStore(string name, string employeeID) public {
  23. employeesCount = 0;
  24. employees[employeesCount] = employee(admin, name, employeeID, authenticationStatus.Active);
  25. employeeAddressIndex[admin] = employeesCount;
  26. employeeNameIndex[name] = employeesCount;
  27. employeeIDIndex[employeeID] = employeesCount;
  28. }
  29.  
  30. function hasAccessByAddress(address account) external constant returns(bool) {
  31. if(employees[employeeAddressIndex[account]].access == authenticationStatus.Active){
  32. return true;
  33. } else return false;
  34. }
  35.  
  36. function gotAccess(address account) public constant returns(authenticationStatus) {
  37. return employees[employeeAddressIndex[account]].access;
  38. }
  39.  
  40. function newEmployee(address account, string name, string employeeID) public {
  41. employeesCount++;
  42. employees[employeesCount] = employee(account, name, employeeID, authenticationStatus.Active);
  43. employeeAddressIndex[account] = employeesCount;
  44. employeeNameIndex[name] = employeesCount;
  45. employeeIDIndex[employeeID] = employeesCount;
  46. emit NewAuthenticationEvent(employeesCount, account, now);
  47. }
Add Comment
Please, Sign In to add comment