-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSalary.sol
80 lines (59 loc) · 1.98 KB
/
Salary.sol
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Salary {
address owner;
mapping (address=>bool) public isEmployee;
mapping (address => Employee) employees;
address[] public allEmployees;
address[] interns;
address[] juniors;
address[] seniors;
enum Position {Intern, Junior, Senior}
struct Employee {
address empAddress;
Position empPosition;
uint salary;
}
constructor(){
owner = msg.sender;
}
// modifier onlyOwner(){
// require(owner == msg.sender);
// _;
// }
// these functions are supposed to use onlyOwner modifier,
// but for judging purpose we have commented the modifier,
// so that judges can test all the functionalities of our applicaiton.
function addEmployee(address payable empAddress, Position _position) public {
isEmployee[empAddress] = true;
uint pay;
if (_position == Position.Intern) {
interns.push(empAddress);
pay = 0.001 ether;
}
else if (_position == Position.Junior) {
juniors.push(empAddress);
pay = 0.002 ether;
}
else if (_position == Position.Senior) {
seniors.push(empAddress);
pay = 0.003 ether;
}
Employee memory newEmployee = Employee(empAddress,_position, pay);
employees[empAddress] = newEmployee;
allEmployees.push(empAddress);
}
function getAllEmployees() public view returns (address[] memory, address[] memory, address[] memory) {
return (interns, juniors, seniors);
}
function payEmployees() public payable {
for (uint i = 0; i < allEmployees.length; i++) {
payable(allEmployees[i]).transfer(employees[allEmployees[i]].salary);
}
}
function getContractBalance() public view returns (uint) {
return address(this).balance;
}
function acceptPayment() public payable {
}
}