Skip to content

Instantly share code, notes, and snippets.

@Apolloelephen
Last active February 9, 2024 15:20
Show Gist options
  • Save Apolloelephen/af09f79bec638cf3e0cb6dc81b077169 to your computer and use it in GitHub Desktop.
Save Apolloelephen/af09f79bec638cf3e0cb6dc81b077169 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import "contracts/school.sol";
contract factory {
School public cms; // Here we are defining the variable cms with the type School which corresponds with the name of the contract we imported.
function CreateSchoolCms() public {
cms = new School();
}
}
// 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