-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskManager.sol
More file actions
186 lines (144 loc) · 6.09 KB
/
taskManager.sol
File metadata and controls
186 lines (144 loc) · 6.09 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
import "./ACOMToken.sol";
contract taskManagerSystem {
AGEMSToken public acomToken;
address public client;
address public user;
address public owner;
bool reentrancyLock;
mapping(address => string) public taskName;
mapping(address => string) public notification;
struct authenticateUser {
uint userId;
string userName;
address userAddress;
}
mapping(address=>authenticateUser) public userAuthentication;
struct taskManager {
bool projectApplied;
string formerProjects;
uint[] skills;
bool taskAssigned;
address taskAssignedTo;
string projectName;
uint projectId;
bool fundsEscrowed;
bool fundsReleased;
uint amount;
}
mapping(address => taskManager) public manageTask;
struct ReviewSystem {
bool reviewed;
bool taskCompleted;
address reviewer;
}
mapping(address => ReviewSystem) public systemOfReview;
// contructor to initialize some state variables
constructor(address _client, address _user, address _acomTokenAddress) {
owner = msg.sender;
client = _client;
user = _user;
acomToken = AGEMSToken(_acomTokenAddress);
}
// onlyClient modifier
modifier onlyClient() {
require(msg.sender == client, "only client can call this function");
_;
}
modifier nonReentrant() {
require(!reentrancyLock, "reentrancyGuard");
reentrancyLock = true;
_;
reentrancyLock = false;
}
// onlyOwner modifier
modifier onlyOwner() {
require(msg.sender == owner, "only owner can call this function");
_;
}
// onlyUser modifier
modifier onlyUser() {
require(msg.sender == user, "only user can call this function");
_;
}
// Authenticate user function
function _authenticateUser(address _user, uint _userId, string memory _userName) external onlyUser onlyClient {
require(_user != address(0), "Address must be valid");
require(userAuthentication[_user].userAddress == address(0), "User already authenticated");
userAuthentication[_user] = authenticateUser(_userId, _userName, _user);
}
// post task function
function postTask(string memory _taskName) external onlyClient {
taskName[msg.sender] = _taskName;
emit NotificationSent(client, "New task posted, users can now apply");
}
// applyForProject function
function applyForProject(uint[] memory skills, string memory _formerProjects) external onlyUser {
require(!manageTask[msg.sender].projectApplied, "Already applied for a project");
manageTask[msg.sender] = taskManager(true, _formerProjects, skills, false, address(0), "", 0, false, false, 0);
}
// Assign project function
function assignProject(address _user, string memory _projectName, uint _projectId, uint _amount) external onlyClient {
require(!manageTask[_user].taskAssigned, "Task already assigned");
manageTask[_user].taskAssigned = true;
manageTask[_user].taskAssignedTo = _user;
manageTask[_user].projectName = _projectName;
manageTask[_user].projectId = _projectId;
manageTask[_user].amount = _amount;
}
// Show skillsets function
function showSkillsets(address _user) external view returns (uint[] memory) {
return manageTask[_user].skills;
}
// Show former projects function
function showFormerProjects(address _user) external view returns (string memory) {
return manageTask[_user].formerProjects;
}
// Escrow funds function
function escrowFunds(uint _amount) external nonReentrant {
taskManager storage task = manageTask[msg.sender];
require(task.taskAssigned, "No task assigned");
require(!task.fundsEscrowed, "Funds already escrowed");
// Transfer ACOM tokens for escrow
require(acomToken.transferFrom(msg.sender, address(this), _amount), "ACOM transfer failed");
task.fundsEscrowed = true;
}
// Review task function
function reviewTask(address _reviewer) external onlyClient onlyUser {
_reviewer = client;
systemOfReview[_reviewer].reviewed = true;
}
// Complete task function
function completeTask(address _reviewer) external onlyClient onlyUser {
_reviewer = client;
systemOfReview[_reviewer].taskCompleted = true;
}
// Pay for task function
function payForTask(address _user) external nonReentrant {
taskManager storage task = manageTask[_user];
require(task.fundsEscrowed && !task.fundsReleased, "Funds not escrowed or already released");
require(systemOfReview[_user].reviewed && systemOfReview[_user].taskCompleted, "Task not reviewed or completed");
// Transfer ACOM tokens for payment
require(acomToken.transfer(task.taskAssignedTo, task.amount), "ACOM transfer failed");
task.fundsReleased = true;
emit NotificationSent(task.taskAssignedTo, "Payment received for task");
}
// Notify function
function notify(address _recipient, string memory _updateType) external onlyClient onlyUser {
string memory notificationMessage;
if (keccak256(abi.encodePacked(_updateType)) == keccak256(abi.encodePacked("update"))) {
notificationMessage = "New update available for the project.";
} else if (keccak256(abi.encodePacked(_updateType)) == keccak256(abi.encodePacked("payment"))) {
notificationMessage = "Payment has been made for the project.";
} else if (keccak256(abi.encodePacked(_updateType)) == keccak256(abi.encodePacked("deadline"))) {
notificationMessage = "Deadline for the project is approaching.";
} else {
revert("Invalid update type.");
}
notification[_recipient] = notificationMessage;
emit NotificationSent(_recipient, notificationMessage);
}
// Notification event
event NotificationSent(address indexed recipient, string notification);
}