Created
November 30, 2018 19:21
-
-
Save wolivera/274243e3b58d78231fcc8ed005f3321f to your computer and use it in GitHub Desktop.
Solidity contract to keep track of documents and its versions
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.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