GymInstructors.sol 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. pragma solidity ^0.4.24;
  2. contract GymInstructors{
  3. address owner;
  4. function GymInstructor() public{
  5. owner = msg.sender;
  6. }
  7. modifier onlyOwner{
  8. require(msg.sender == owner);
  9. _;
  10. }
  11. struct Instructor{
  12. string fName;
  13. string lName;
  14. uint age;
  15. string field;
  16. }
  17. mapping(address => Instructor) instructors;
  18. address[] public instructorAccounts;
  19. //sets the info for a new instructor
  20. function setInstructor(address _address, string _fName, string _lName, uint _age, string _field)onlyOwner public{
  21. var instructor = instructors[_address];
  22. instructor.fName = _fName;
  23. instructor.lName = _lName;
  24. instructor.age = _age;
  25. instructor.field = _field;
  26. instructorAccounts.push(_address) -1 ;
  27. }
  28. //returns all the instructor accounts
  29. function getInstructors() public returns(address[]){
  30. return instructorAccounts;
  31. }
  32. //returns the info of an instructor specified by address
  33. function getInstructor(address _address) view public returns(string fn, string ln, uint a, string fld){
  34. return(instructors[_address].fName, instructors[_address].lName, instructors[_address].age, instructors[_address].field);
  35. }
  36. //returns the total number of available instructors
  37. function countAllInstructors() public returns(uint){
  38. return instructorAccounts.length;
  39. }
  40. //returns true if a certain instructor is specialized in the given field, false otherwise
  41. function checkField(address _address, string _field) public returns(bool){
  42. require(keccak256(abi.encodePacked(instructors[_address].field)) == keccak256(abi.encodePacked(_field)));
  43. return true;
  44. }
  45. }