//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.18; contract FreelancerContract { // Structure to represent a task struct Task { address client; // Address of the client who created the task uint value; // Amount of ether set for the task bool completed; // Flag to indicate if the task is completed bool paid; // Flag to indicate if the task is paid } // Array to store all the tasks Task[] public tasks; // Events to emit when tasks are created, completed, and paid event TaskCreated(uint indexed taskId, address indexed client, uint value); event TaskCompleted(uint indexed taskId); event TaskPaid(uint indexed taskId); // Function to create a new task function createTask() public payable { require(msg.value > 0); Task memory newTask = Task({ client: msg.sender, value: msg.value, completed: false, paid: false }); uint newTaskId = tasks.push(newTask) - 1; TaskCreated(newTaskId, msg.sender, msg.value); } // Function to complete a task function completeTask(uint taskId) public { require(taskId < tasks.length); require(tasks[taskId].client == msg.sender); require(!tasks[taskId].completed); tasks[taskId].completed = true; TaskCompleted(taskId); } // Function to release payment for a completed task function releasePayment(uint taskId) public { require(taskId < tasks.length); require(tasks[taskId].completed); require(!tasks[taskId].paid); tasks[taskId].paid = true; address freelancerAddress = msg.sender; uint paymentAmount = tasks[taskId].value; freelancerAddress.transfer(paymentAmount); TaskPaid(taskId); } // Function to get the total number of tasks function getTaskCount() public view returns (uint) { return tasks.length; } // Function to get the details of a specific task function getTaskDetails(uint taskId) public view returns (address client, uint value, bool completed, bool paid) { require(taskId < tasks.length); Task memory task = tasks[taskId]; return (task.client, task.value, task.completed, task.paid); } }
0.4.18