Skip to content

Instantly share code, notes, and snippets.

@Zeegaths
Last active February 8, 2024 22:47
Show Gist options
  • Save Zeegaths/40de5900fbdd45a42b25a66b65b2a2c8 to your computer and use it in GitHub Desktop.
Save Zeegaths/40de5900fbdd45a42b25a66b65b2a2c8 to your computer and use it in GitHub Desktop.
School database
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract School {
enum Rank {
Principle,
Teacher,
Student
}
struct Person {
string Name;
uint Age;
uint Score;
address Account;
Rank rank;
}
address public principle;
mapping(address => mapping(Rank => Person)) private database;
constructor() {
principle = msg.sender;
}
modifier onlyPrinciple {
require(principle == msg.sender, "Only principle have full access");
_;
}
modifier onlyTeacher {
require(database[msg.sender][Rank.Teacher].Account == msg.sender, "Only teacher can update score");
_;
}
function registerStudent (address _studentAddress, string memory _name, uint _age, uint _score) onlyPrinciple public {
database[_studentAddress][Rank.Student] = Person(_name, _age, _score, _studentAddress, Rank.Student);
}
function registerTeacher (address _teacherAddress, string memory _name, uint _age, uint _Score) public onlyPrinciple {
database[_teacherAddress][Rank.Teacher] = Person(_name, _age, _Score, _teacherAddress, Rank.Teacher);
}
function updateScore(address _studentAddress, uint sscore) public onlyTeacher {
database[_studentAddress][Rank.Student].Score = sscore;
}
function removeTeacher( address _teacherAddress) public onlyPrinciple {
database[_teacherAddress][Rank.Teacher].Account = _teacherAddress;
delete(_teacherAddress);
}
}
// pragma solidity ^0.8.0;
// contract School {
// enum Rank {
// Principle,
// Teacher,
// Student
// }
// struct Person {
// string Name;
// uint Age;
// uint Score;
// Rank rank;
// }
// Rank private rank;
// address public principle;
// address public teacherAddress;
// address public studentAddress;
// mapping(address => mapping(Rank => Person)) private database;
// constructor() {
// principle = msg.sender;
// }
// modifier onlyPrinciple {
// require(principle == msg.sender, "Only principle have full access");
// _;
// }
// modifier onlyTeacher {
// require(teacherAddress == msg.sender, "Only teacher can update score");
// _;
// }
// function registerStudent (address _studentAddress, string memory _name, uint _age, uint _score) onlyPrinciple public returns (string memory, uint){
// studentAddress = _studentAddress;
// Person memory person;
// person.Name =_name;
// person.Age = _age;
// person.Score = _score;
// return(person.Name, person.Age);
// }
// function registerTeacher (address _teacherAddress, string memory _name, uint _age) public onlyPrinciple returns (address, Rank, string memory, uint){
// teacherAddress = _teacherAddress;
// Person memory person;
// person.rank = Rank.Teacher;
// person.Name =_name;
// person.Age = _age;
// return(teacherAddress, rank, person.Name, person.Age);
// }
// function updateScore(address _studentAddress, uint sscore) public payable onlyTeacher {
// // require(rank = Rank.Teacher);
// studentAddress = _studentAddress;
// Person memory person;
// person.Score = sscore;
// }
// function removeTeacher( address _teacherAddress) public onlyPrinciple {
// teacherAddress = _teacherAddress;
// delete(teacherAddress);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment