forked from linjie-1/guigulive-operation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment #1
62 lines (51 loc) · 1.69 KB
/
Assignment #1
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
pragma solidity ^0.4.14;
contract Payroll {
uint salary = 1 ether;
uint constant payDuration = 20 seconds;
uint lastPayDay = now;
uint nextPayDay;
uint payment;
//set up initial emloyee address
address employer = 0xca35b7d915458ef540ade6068dfe2f44e8fa733c;
address employee = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c;
function addFund() payable returns (uint){
return this.balance;
}
//update employee address
function changeEmployee(address e){
require(msg.sender == employer);
if (employee != 0x0){
//pay accumulated salary to former employee
payment = salary * (now - lastPayDay) / payDuration;
lastPayDay = now;
employee.transfer(payment);
}
employee = e;
}
//update employee salary
function changeSalary(uint s){
require(msg.sender == employer);
if (employee != 0x0) {
//pay accumulated salary to the current employee
payment = salary * (now - lastPayDay) / payDuration;
lastPayDay = now;
employee.transfer(payment);
}
salary = s * 1 ether;
}
function calculateRunway() returns (uint){
return this.balance/salary;
}
function hasEnoughFund() returns (bool){
return calculateRunway() > 0;
}
//updated
function getPaid(){
require(msg.sender == employee);
nextPayDay = lastPayDay + payDuration;
assert(nextPayDay <= now);
lastPayDay = nextPayDay;
payment = salary * (now - lastPayDay) / payDuration;
employee.transfer(payment);
}
}