The RewardSystem smart contract is designed to facilitate a reward system on the Tari Network. It allows users to create tasks, offer rewards for task completion, and manage the acceptance and distribution of rewards. Here's an in-depth description of how the program works, its intended functionality, and how to use it:
Task Creation:
Users can create a task by calling the createTask function, providing the necessary parameters such as the task topic, description, symbol, timer, minimum reward, and initial deposit.
The function creates a new task with a unique task ID and stores it in the tasks mapping. The task's initial deposit is added to the contract and the user's balance is updated accordingly.
An event is emitted to notify the creation of the task.
Reward Addition:
Users can add rewards to an existing task by calling the addReward function and providing the task ID and the reward amount.
The function checks that the task exists and the reward amount meets the minimum requirement.
The reward amount is added to the task's total reward and the user's balance is updated.
An event is emitted to notify the addition of the reward.
Task Completion Candidate:
Once a user completes a task, they can submit their proof of completion by calling the taskCompletionCandidate function with the task ID, proof text, and proof binary data.
The function increments the completion count for the task, indicating that a candidate has claimed completion.
An event is emitted to notify the task completion.
Task Acceptance:
Users who deposited rewards for a task can accept or reject a candidate's claim by calling the acceptTask function with the task ID.
The function checks that the task exists and the user hasn't already accepted the task.
If more than two-thirds of the minted tokens for the task accept the completion, the user who completed the task receives the full reward.
The user's token balance is adjusted, and if the task is accepted, the reward is transferred to the task completion candidate.
An event is emitted to notify the acceptance of the task.
Withdrawal Timeout:
If a task is not considered complete and the timer expires, users can withdraw their equivalent deposited amount by calling the withdrawalTimeout function.
The function checks the user's balance and transfers the equivalent amount of ETH back to their address.
Permanent Expiration:
After five years have passed since the task's timer expiration, users can call the withdrawalTimeout2 function with the task ID.
The function checks if the task exists and has expired.
The remaining ETH in the task is transferred to the task completion candidate, and the task is marked as permanently expired.
Task Listing:
Users can retrieve a list of open tasks, including their IDs, subjects, total rewards, and the number of completion candidates, by calling the listTasks function.
The function iterates through the tasks and retrieves the required information.
The information is returned as arrays.
To use the smart contract, users interact with it by invoking the public functions using their wallets or smart contract interaction tools on the Tari Network. They can create tasks, add rewards, claim task completion, accept or reject task completion claims, withdraw rewards, and retrieve task listings.