Created
October 15, 2015 13:25
-
-
Save anonymous/5206b492337822012dec to your computer and use it in GitHub Desktop.
Created using soleditor: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity?gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @title: Datagotchi | |
// @author: Doug A <d11e9@turkd.net> | |
// @desc: distributed data modeling | |
contract datagotchi { | |
struct HashedResponse { | |
address creator; | |
bytes32 hashedReponse; | |
uint modelIndex; | |
} | |
struct Model { | |
address creator; | |
bytes32 modelContentHash; | |
} | |
struct Job { | |
address creator; | |
bytes32 sampleDataContentHash; | |
bytes32 hashedDataContentHash; | |
bytes32 docsContentHash; | |
bytes32[] challenges; | |
bytes32[] responses; | |
uint bounty; | |
} | |
mapping( uint => Job ) public jobs; | |
mapping( uint => Model[] ) public jobModels; | |
mapping( bytes32 => HashedResponse[] ) challengeHashedResponses; | |
uint public latestJob; | |
uint public jobsOutstanding; | |
function submitJob(bytes32 sample, bytes32 hashedData) { | |
bytes32[] memory tmpBytesArr; | |
bytes32 tmpBytes; | |
jobs[latestJob++] = Job(msg.sender, sample, hashedData, tmpBytes, tmpBytesArr,tmpBytesArr, msg.value ); | |
jobsOutstanding++; | |
} | |
function submitModel(uint jobId, bytes32 modelContentHash) returns (uint modelIndex) { | |
jobModels[jobId][++jobModels[jobId].length - 1] = Model( msg.sender, modelContentHash ); | |
return jobModels[jobId].length; | |
} | |
function submitModelWithChallengeAndHashedResponse( uint jobId, bytes32 modelContentHash, bytes32 challenge, bytes32 hashedResponse) { | |
uint modelIndex = submitModel( jobId, modelContentHash ); | |
submitChallenge( jobId, challenge ); | |
submitHashedResponse( jobId, modelIndex, challenge, hashedResponse); | |
} | |
function submitChallenge (uint jobId, bytes32 challenge) private { | |
jobs[jobId].challenges[++jobs[jobId].challenges.length - 1] = challenge; | |
} | |
function submitResponse(uint jobId, bytes32 challenge, bytes32 response) { | |
jobs[jobId].responses[++jobs[jobId].responses.length - 1] = response; | |
} | |
function submitHashedResponse(uint jobId, uint modelIndex, bytes32 challenge, bytes32 hashedResponse) private { | |
HashedResponse memory hr = HashedResponse( msg.sender, hashedResponse, modelIndex ); | |
challengeHashedResponses[challenge][++challengeHashedResponses[challenge].length - 1] = hr; | |
} | |
function closeJob(uint jobId) { | |
if (msg.sender == jobs[jobId].creator) { | |
Job memory job = jobs[jobId]; | |
if (job.challenges.length == 0) { | |
msg.sender.send( job.bounty ); | |
delete jobs[jobId]; | |
jobsOutstanding--; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment