//Oscar Ibarhuen-Guereca pragma solidity >=0.4.22 <0.6.0; contract Duties { //The address is the variable that acts as the parties involved in the contract, in this case, the roomates on the agreement. address payable [] roommates; //The following are the units that are used throughout the contract, including the timer, stake, if the task was done within five or seven days and if the task has been completed. uint totalRoommates; uint timeLapse = now - checkTime; uint taskId; uint sTime; uint checkTime; uint constant stake = 100; uint constant fiveDays = 5; uint constant sevenDays = 7; mapping (uint => bool) taskComplete; //The following booleans will detect if the following variables apply or not. bool isPayable_ = false; bool isLessFiveDay_ = false; bool isAssignedCompleted_ = false; bool isGreaterFiveDay_ = false; //The events are situations that can happen throughout the time this smart contract is active. //In the scenario that there no more tasks to perform, event noDuties(string Msg); event doneAdmin(string Msg, uint taskId, bool isComplete, bool isPayable, bool isLessFiveSec, uint startTime, uint currentTime); event doneRoomate(string Msg, uint taskId, bool isAssignedCompleted, bool isTaskCompleted,bool isPayable, bool isGreaterFiveSec, uint startTime, uint currentTime); event transactionEvent(bool done); //To start the contract in the blockchain, the constructor is essential to begin the contract with the elements (in this case the roomates) to begin the contract. constructor(uint totalRoommates_) public { totalRoommates = totalRoommates_; } //The modifier for the oneRoomate means that when we define the function, we will do it per roomates individually. modifier oneRoommate() { _; } //The following funtion will assign the duties to each roomate. function assign() public payable { if (totalRoommates != 4) { roommates.push(msg.sender); taskComplete[roommates.length] = false; totalRoommates += 1; if (totalRoommates == 4){ //Once there are four roomates, the timer will begin at this point. checkTime = now; } } //Once there are four roomates, this loop will finish. else{ emit noDuties("There are no more"); } } //After we have defined the four roomates, we will continue with the hearth of the contract, which is the tracking of the duties to be completed. //In the declaration of the function to track the duties process, we will call the modifier in here to track each roomate individually. function Tracker(uint taskId_) public oneRoommate { if(roommates[taskId_] == msg.sender){ //In the following, we will check if the task has been completed, if not, then we will check if it done, and if so, we will procede to change this task to done. if(taskComplete[taskId_] == false){ taskComplete[taskId_] = true; //Once that happened, now we check if it was executed within five days. if(timeLapse <= fiveDays){ //if so, we will procede to make payable and less than five days variables to true, meaning that the roomate has done this task within the time limit period. isPayable_ = true; isLessFiveDay_ = true; if (!address(msg.sender).send(stake)) { emit transactionEvent(true); } } //Otherwise, we will procedure with the event below to check the status of that assignment. emit doneAdmin("Task complete.", taskId_, taskComplete[taskId_], isPayable_, isLessFiveDay_, checkTime, timeLapse); } //If the task has not been completed as the if assignment states, then it means that the task has been done already. else{ emit doneAdmin("Task previously done.", taskId_, taskComplete[taskId_], isPayable_, isLessFiveDay_, checkTime, timeLapse); } } else{ for(uint i=0; i<roommates.length; i++){ if(roommates[i] == msg.sender){ if(taskComplete[i] == true){ if(taskComplete[taskId_] == false){ isAssignedCompleted_ = true; taskComplete[taskId_] = true; timeLapse = now - checkTime; //If the task has been done between five days and seven days, we will procede with the following conditions. if((timeLapse >= fiveDays) && (timeLapse <= sevenDays)){ if (!address(msg.sender).send(stake)) { emit transactionEvent(true); } emit doneAdmin("Another roomate finish the task!", taskId_, taskComplete[taskId_],isPayable_, isGreaterFiveDay_, checkTime, timeLapse); } else{ emit doneRoomate("Time period ended.", taskId_, isAssignedCompleted_, taskComplete[taskId_],isPayable_, isGreaterFiveDay_, checkTime, timeLapse); } } else{ emit doneRoomate("Task previously done.", taskId_, isAssignedCompleted_, taskComplete[taskId_],isPayable_, isGreaterFiveDay_, checkTime, timeLapse); } } } } } } }
0.4.25