Skip to content

Instantly share code, notes, and snippets.

@wolivera
Created November 30, 2018 19:21
Show Gist options
  • Save wolivera/274243e3b58d78231fcc8ed005f3321f to your computer and use it in GitHub Desktop.
Save wolivera/274243e3b58d78231fcc8ed005f3321f to your computer and use it in GitHub Desktop.
Solidity contract to keep track of documents and its versions
pragma solidity ^0.4.24;
contract DocumentTrackContract {
struct Document {
DocumentVersion[] versions;
}
struct DocumentVersion {
bytes32 hash;
uint32 date;
string data;
}
address public owner = msg.sender;
// stored documents and versions
mapping (string => mapping (bytes32 => bool)) private proofs;
mapping (string => Document) private documents;
modifier ownerOnly {
if (msg.sender == owner) _;
}
// calculate and store the proof for a document
function notarize(string id, bytes32 hash) external ownerOnly {
DocumentVersion memory version = DocumentVersion({ hash: hash });
documents[id].versions.push(version);
proofs[id][hash] = true;
}
function exists(string id, string hash) public view returns (bool) {
return proofs[id][hash];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment