Created
January 9, 2018 04:53
-
-
Save noman-land/240f5c4d0bbb33155fb19f869d5c22df to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.4.11; | |
contract Wiki { | |
function Wiki() { | |
} | |
struct Diff { | |
address owner; | |
uint currentSwarmHash; | |
uint previousSwarmHash; | |
} | |
uint numEdits; | |
uint lastEditedBlock; | |
address lastEditedBy; | |
mapping (uint => uint) diffIndexes; | |
Diff[] diffs; | |
function update( | |
uint currentDiffSwarmHash, | |
uint previousDiffSwarmHash | |
) { | |
uint previousIndex = diffIndexes[previousDiffSwarmHash]; | |
uint previousCurrentHash = diffs[previousIndex].currentSwarmHash; | |
if ( | |
numEdits > 0 | |
&& currentDiffSwarmHash != previousCurrentHash | |
) { | |
throw; | |
} | |
numEdits = numEdits + 1; | |
lastEditedBlock = block.number; | |
lastEditedBy = msg.sender; | |
diffIndexes[currentDiffSwarmHash] = diffIndexes[currentDiffSwarmHash] + 1; | |
diffs.push( | |
Diff( | |
msg.sender, | |
currentDiffSwarmHash, | |
previousDiffSwarmHash | |
) | |
); | |
} | |
function getNumEdits() returns (uint) { | |
return numEdits; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment