pragma solidity ^0.4.18; contract Decentralized_Computations { uint numJobs; struct Job{ string name; // job name string description; // job description address publisher; //address of person who submitted the job uint amount; // amount he is willing to pay bool payment_status; // status of payment recieved or not bool status; // status of job completion string map_code_hash; // mapper code string reduce_code_hash; // reduce code string result_hash; // job result hash uint num_tasks; mapping (uint => Task) all_tasks; // list of all tasks {key:task_data,value:task} } mapping (uint => Job) alljobs; //list of all jobs struct Task{ string data_hash; // task data hash uint amount; // amount to be paid for task bool status; // status of task completion string output_hash; // output of task address website_address; // website which completed the task } struct website{ string url; //url of website address website_address; //address for transferring funds } mapping (uint => website[]) subscribed_websites; // all the websites who subscribed to job {job:[websites]} function createJob(string name,string desc,address pub,uint amt,string map_hash,string reduce_hash) public payable returns (bool success){ numJobs = numJobs++; // numJobs is global variable Job job = alljobs[numJobs]; job.name = name; job.description = desc; job.publisher = pub; job.amount = amt; job.payment_status=true; job.status=false; job.map_code_hash = map_hash; job.reduce_code_hash = reduce_hash; return true; } function addTasks(uint jobid,uint amount,string hash) public returns (bool success){ Job job = alljobs[jobid]; Task task = job.all_tasks[job.num_tasks++]; task.data_hash = hash; task.status = false; task.amount=amount; return true; } function subscribeJob(uint jobid,string url,address web_address) public returns (bool success){ website[] websites = subscribed_websites[jobid]; website memory site; site.url = url; site.website_address = web_address; websites.push(site); return true; } function confirmTaskCompletion(uint jobid,uint taskid,address subscriber) public returns (bool success){ Job job = alljobs[jobid]; Task task = job.all_tasks[taskid]; subscriber.transfer(task.amount); task.status=true; return true; } function confirmJobCompletion(uint jobid) public returns (bool){ Job job = alljobs[jobid]; bool counter=true; for(uint i=0; i<job.num_tasks; i++){ Task task=job.all_tasks[i]; if(task.status==false) counter=false; } if(counter==true) job.status=true; return true; } }
0.4.18