-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtaskContract.sol
131 lines (89 loc) · 3.65 KB
/
taskContract.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
pragma solidity ^0.4.2;
import "./userContract.sol";
contract TaskContract is UserContract {
// groups together various information regarding the task contracts created by the task poster
// struct taskContractStruct{
// address contractAddress ;
// address workerAddress ;
// string taskTitle;
// }
//stores information related to the task registrations received by the task poster
/* struct registrationStruct{
uint taskId ;
address workerAddress;
}
*/
// stores various information of the task
struct taskStruct{
//uint taskId ;
string taskTitle ;
string taskMaterialsHash ;
//string taskSkills;
bool isTaskComplete; //asses requirement of this param
bool isTaskAssigned;
uint256 taskReward ; //stored in wei
uint TP_creator_id;
}
taskStruct[] public tasks;
uint public tasksCount = 0;
//mapping (taskposterID => uint[] ) taskposter_to_tasks //could need
function getTasksCount() public constant returns(uint count) {
return tasks.length;
}
// called when task poster wants to post a task
function postTask( string _taskTitle , string _taskHash, uint256 _taskReward) external {
require(isTaskPoster[msg.sender] == true);
uint id = tasks.push(taskStruct(_taskTitle, _taskHash, false, false, _taskReward, addressToIdTaskPoster[msg.sender])) - 1;
tasksCount++;
}
mapping (uint => uint[]) public taskIdToRegisteredWorkersId; //people who have applied for this task //public for testing
function showRegisteredWorkers(uint taskID) public view returns(uint[]){
uint i = 0 ;
uint counter = 0;
uint noOfRegistered = taskIdToRegisteredWorkersId[taskID].length;
uint[] memory ids_of_registered_workers = new uint[](noOfRegistered);
for(i; i<noOfRegistered;i++){
ids_of_registered_workers[counter] = i;
counter++;
}
/* } */
return ids_of_registered_workers;
}
function showAvailableTasks() public view returns(uint[]) {
uint counter = 0;
uint i = 0;
uint[] memory ids_of_unassignedTasks = new uint[](tasksCount);
/* if(isTaskPoster[msg.sender]){
uint temp = addressToIdTaskPoster[msg.sender];
for(; i<tasks.length;i++){
if (tasks[i].TP_creator_id == temp && !tasks[i].isTaskComplete) {
ids_of_unassignedTasks[counter] = i;
counter++;
}
}
}
else { */
for(; i<tasks.length;i++){
if (tasks[i].isTaskAssigned == false) {
ids_of_unassignedTasks[counter] = i;
counter++;
}
}
/* } */
return ids_of_unassignedTasks;
}
function markTaskComplete(uint _id) public { //public for testing
//require(isTaskPoster[msg.sender]); //BEWARE: any task poster can do this
tasks[_id].isTaskComplete = true;
}
function markTaskAssigned(uint _id) public { //public for testing
//require(isTaskPoster[msg.sender] ); //BEWARE: any task poster can do this
tasks[_id].isTaskAssigned = true;
tasksCount--;
}
function registerForTask(uint _taskId) external {
require(isTaskPoster[msg.sender] == false);
//tasks[_taskId].registeredWorkersId.push(addressToIdWorker[msg.sender]);
taskIdToRegisteredWorkersId[_taskId].push(addressToIdWorker[msg.sender]);
}
}