-
Notifications
You must be signed in to change notification settings - Fork 0
/
workorder.sol
40 lines (33 loc) · 1.05 KB
/
workorder.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
pragma solidity ^0.4.19;
contract WorkOrder {
address public creator;
address public worker;
uint public creationTime;
uint public amount;
bool completed = false;
modifier onlyBy(address _account) { require(msg.sender == _account); _; }
modifier notCompleted() { require(!completed); _; }
modifier hasWorker() { require(worker != address(0)); _; }
event workerPaidOut(uint amount, uint completedTime);
event workorderCanceled(uint amount, uint canceledTime);
event workerAdded(address worker, uint addedTime);
function WorkOrder() public payable {
amount = msg.value;
creator = msg.sender;
creationTime = now;
}
function addWorker(address workeraccount) onlyBy(creator) notCompleted public {
worker = workeraccount;
workerAdded(worker, now);
}
function payoutWorker() public onlyBy(creator) notCompleted hasWorker {
completed = true;
workerPaidOut(amount, now);
worker.transfer(amount);
}
function cancel() public onlyBy(creator) notCompleted {
completed = true;
workorderCanceled(amount, now);
creator.transfer(amount);
}
}