Metadata: string; an uri to locate the json file describing the metadata of this task.
Deadline: uint64; unix time stamp (in seconds) before which the task should be finished. If not finished before the deadline, the task can be refunded by the manager.
Budget: ERC20Transfer[] (tuple(address,uint96)); a list of ERC20 contract addresses and the amount of this token that is up for budget. At task creation this amount of ERC20 tokens will be transfer from the sender of the transaction to an escrow contract. This means the Tasks contract should be approved to spend this amount of ERC20 tokens beforehand.
Manager: address; the address that will have the permission to manage the task, such as approving applicants and reviewing submissions. This allows the funder to give this responsibility to someone else.
Preapprove: PreapprovedApplication[] (tuple(address, Reward[] (tuple(bool, address, uint88))); these addresses will get an approved application on task creation. This can be used to save gas on internal tasks or motivate a contributor to take your task, by making it easier for them to take it.
Outputs
TaskId: uint256; the id of the newly created task. Note: currently Solidity does not give the return value of transactions, you can extract this id from the TaskCreated event in the transaction receipt logs instead.
TaskId: uint256; the id of the task you wish to cancel.
Explanation: string; the uri to why you would like to cancel this task.
Outputs
CancelTaskRequestId: uint8; in case the task is able to be cancelled instantly, this will return 255. Otherwise it will return the id of the request that has been made.
Code
```solidity
function cancelTask(
uint256 _taskId,
string calldata _explanation
) external returns (uint8 cancelTaskRequestId) {
_ensureNotDisabled();
Task storage task = _getTask(_taskId);
_ensureSenderIsManager(task);
_ensureTaskNotClosed(task);
if (
task.state == TaskState.Open ||
task.deadline <= uint64(block.timestamp)
) {
// Task is open or deadline past
if (task.state == TaskState.Open) {
unchecked {
--openTasks;
}
} else {
// if (task.state == TaskState.Taken) {
unchecked {
--takenTasks;
}
}
_refundCreator(task);
emit TaskCancelled(
_taskId,
_msgSender(),
task.state == TaskState.Open
? address(0)
: task.applications[task.executorApplication].applicant
);
// Max means no request
cancelTaskRequestId = type(uint8).max;
} else {
// Task is taken and deadline has not past
CancelTaskRequest storage request = task.cancelTaskRequests[
task.cancelTaskRequestCount
];
request.explanation = _explanation;
cancelTaskRequestId = task.cancelTaskRequestCount++;
emit CancelTaskRequested(
_taskId,
cancelTaskRequestId,
_explanation,
_msgSender(),
task.applications[task.executorApplication].applicant
);
}
}
```
Accept request
Inputs
TaskId: uint256; the id of the task you want to accept a request from.
RequestType: RequestType (uint8); the type of request you want to accept.
RequestId: uint8; the id of the request you want to accept.
Execute: bool; if you want to execute the request in this transaction.
Code
```solidity
function acceptRequest(
uint256 _taskId,
RequestType _requestType,
uint8 _requestId,
bool _execute
) external {
_ensureNotDisabled();
Task storage task = _getTask(_taskId);
_ensureTaskIsTaken(task);
_ensureSenderIsExecutor(task);
//if (_requestType == RequestType.CancelTask) {
{
_ensureCancelTaskRequestExists(task, _requestId);
CancelTaskRequest storage cancelTaskRequest = task
.cancelTaskRequests[_requestId];
_ensureRequestNotAccepted(cancelTaskRequest.request);
if (_execute) {
// use executeRequest in the body instead? (more gas due to all the checks, but less code duplication)
unchecked {
--takenTasks;
}
_refundCreator(task);
emit TaskCancelled(_taskId, task.manager, _msgSender());
cancelTaskRequest.request.executed = true;
}
cancelTaskRequest.request.accepted = true;
}
emit RequestAccepted(
_taskId,
_requestType,
_requestId,
task.manager,
_msgSender()
);
}
```
Execute request
Inputs
TaskId: uint256; the id of the task you want to execute a request from.
RequestType: RequestType (uint8); the type of request you want to execute.
RequestId: uint8; the id of the accepted request you want to execute.
TaskId: uint256; the id of the task you want to increase the budget of.
Increase: uint96[]; the amount to increase the budget by. This array should be the same length as the budget array. Each item will increase the budget entry with the same array index.