Skip to content

Instantly share code, notes, and snippets.

@Apolloelephen
Created February 7, 2024 19:55
Show Gist options
  • Save Apolloelephen/e0941e0a99a9018a27128b10dfd5d378 to your computer and use it in GitHub Desktop.
Save Apolloelephen/e0941e0a99a9018a27128b10dfd5d378 to your computer and use it in GitHub Desktop.
School Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract School {
address public principal;
mapping(address => bool) public teachers;
mapping(address => Student) public students;
struct Student {
string name;
uint256 grade;
string contactInfo;
}
event StudentRecord(address indexed student, string updatedInfo);
event TeacherAdded(address indexed teacher);
modifier onlyPrincipal() {
require(msg.sender == principal, "Only the principal can perform this action");
_;
}
modifier onlyTeacher() {
require(teachers[msg.sender], "Only teachers can perform this action");
_;
}
constructor() {
principal = msg.sender;
}
function addStudentRecord(address studentAddress, string memory name, uint256 grade, string memory contactInfo) external onlyPrincipal {
students[studentAddress] = Student(name, grade, contactInfo);
}
function updateStudentRecord(string memory updatedInfo) external {
students[msg.sender].contactInfo = updatedInfo;
emit StudentRecord(msg.sender, updatedInfo);
}
function addTeacher(address teacherAddress) external onlyPrincipal {
teachers[teacherAddress] = true;
emit TeacherAdded(teacherAddress);
}
function updateStudentScore(address studentAddress, uint256 subject, uint256 newScore) external onlyTeacher {
}
function viewStudentRecord(address studentAddress) external view returns (string memory name, uint256 grade, string memory contactInfo) {
Student storage student = students[studentAddress];
return (student.name, student.grade, student.contactInfo);
}
function viewTeacherRecord(address teacherAddress) external view returns (bool) {
return teachers[teacherAddress];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment