Skip to content

Instantly share code, notes, and snippets.

@noman-land
Created January 9, 2018 04:53
Show Gist options
  • Save noman-land/240f5c4d0bbb33155fb19f869d5c22df to your computer and use it in GitHub Desktop.
Save noman-land/240f5c4d0bbb33155fb19f869d5c22df to your computer and use it in GitHub Desktop.
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