-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentFeeSystem.sol
More file actions
48 lines (39 loc) · 1.38 KB
/
Copy pathStudentFeeSystem.sol
File metadata and controls
48 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract StudentFeeSystem {
address public owner;
mapping(address => uint) public studentFees;
uint public totalFeesCollected;
event FeesPaid(address indexed student, uint amount);
event FeesWithdrawn(address indexed owner, uint amount);
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can perform this action");
_;
}
function payFees() public payable {
require(msg.value > 0, "Fees must be greater than 0");
studentFees[msg.sender] += msg.value;
totalFeesCollected += msg.value;
emit FeesPaid(msg.sender, msg.value);
}
function withdrawFees(uint _amount) public onlyOwner {
require(_amount <= address(this).balance, "Insufficient contract balance");
payable(owner).transfer(_amount);
totalFeesCollected -= _amount;
emit FeesWithdrawn(owner, _amount);
}
function getStudentFees(address _student) public view returns (uint) {
return studentFees[_student];
}
function getContractBalance() public view returns (uint) {
return address(this).balance;
}
receive() external payable {
studentFees[msg.sender] += msg.value;
totalFeesCollected += msg.value;
emit FeesPaid(msg.sender, msg.value);
}
}