Skip to content

Instantly share code, notes, and snippets.

@d11e9
Created October 15, 2015 17:06
Show Gist options
  • Save d11e9/d59588a87989a859851a to your computer and use it in GitHub Desktop.
Save d11e9/d59588a87989a859851a to your computer and use it in GitHub Desktop.
// @title: Datagotchi
// @author: Doug A <d11e9@turkd.net>
// @desc: distributed data modeling
contract datagotchi {
struct Challenge {
bytes32 challenge;
bytes32 hashedResponse;
bytes32 response;
}
struct Model {
address creator;
uint jobId;
bytes32 modelContentHash;
bytes32[] responses;
uint meanSqErr;
}
struct Job {
address creator;
bytes32 sampleDataContentHash;
bytes32 docsContentHash;
uint[] challenges;
uint[] models;
uint bounty;
}
mapping( uint => Job ) public jobs;
mapping( uint => Model ) public models;
mapping( uint => Challenge ) challenges;
uint public jobCounter;
uint modelCounter;
uint challengeCounter;
function submitJob(bytes32 sample) {
uint[] memory tmpUintArr;
bytes32 tmpBytes;
jobs[jobCounter++] = Job(msg.sender, sample, tmpBytes, tmpUintArr, tmpUintArr, msg.value );
}
function submitModel(uint jobId, bytes32 modelContentHash) returns (uint modelId) {
bytes32[] memory tmpBytesArr;
jobs[jobId].models[++jobs[jobId].models.length - 1] = modelCounter;
models[modelCounter++] = Model( msg.sender, jobId, modelContentHash, tmpBytesArr, uint(0) );
return modelCounter;
}
function submitChallenge (uint jobId, bytes32 challenge, bytes32 hashedResponse) {
if (msg.sender == jobs[jobId].creator ) {
jobs[jobId].challenges[++jobs[jobId].challenges.length - 1] = challengeCounter;
challenges[challengeCounter++] = Challenge( challenge, hashedResponse, bytes32(0) );
}
}
function submitHashedResponse(uint modelId, uint challengeIndex, bytes32 hashedResponse) private {
if (msg.sender == models[modelId].creator ) {
if (models[modelId].responses.length < challengeIndex + 1)
models[modelId].responses.length = challengeIndex + 1;
models[modelId].responses[challengeIndex] = hashedResponse;
}
}
function evaluateModel(uint modelId) {
uint err;
for (uint i = 0; i < jobs[models[modelId].jobId].challenges.length; i++) {
// TODO :)
}
}
function submitUnhashedReponse(uint jobId, uint challengeIndex, bytes32 unhashedResponse){
// TODO :)
}
function removeModel(uint modelId) {
if (msg.sender == models[modelId].creator) {
delete models[modelId];
}
}
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];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment