-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesson1-18-kevin-zhang.sol
48 lines (42 loc) · 1.15 KB
/
lesson1-18-kevin-zhang.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
pragma solidity ^0.4.14;
contract Payroll {
uint salary = 1 ether;
address employeeAddress;
address employerAddress = 0xdd870fa1b7c4700f2bd7f44238821c26f7392148;
uint constant payDuration = 30 days;
uint lastPayday = now;
function addFund() payable returns (uint) {
return this.balance;
}
function calculateRunway() returns (uint) {
return this.balance / salary;
}
function hasEnoughFund() returns (bool) {
return calculateRunway() > 0;
}
function getPaid() {
if(msg.sender != employeeAddress) {
revert();
}
uint nextPayday = lastPayday + payDuration;
if(nextPayday > now) {
revert();
}
lastPayday = nextPayday;
employeeAddress.send(salary);
}
function updateEmployee(address newEmployee, uint newSalary) {
if(msg.sender != employerAddress) {
revert();
}
if(newEmployee == 0x0) {
revert();
}
if(newSalary == 0) {
revert();
}
employeeAddress = newEmployee;
salary = newSalary;
lastPayday = now;
}
}