ProofOfExistence.sol 1004 B

12345678910111213141516171819202122232425262728293031323334353637
  1. pragma solidity ^0.4.4;
  2. /*
  3. * Proof of Existence example contract
  4. * see https://medium.com/zeppelin-blog/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05
  5. */
  6. contract ProofOfExistence {
  7. mapping (bytes32 => bool) public proofs;
  8. // store a proof of existence in the contract state
  9. function storeProof(bytes32 proof) {
  10. proofs[proof] = true;
  11. }
  12. // calculate and store the proof for a document
  13. function notarize(string document) {
  14. var proof = calculateProof(document);
  15. storeProof(proof);
  16. }
  17. // helper function to get a document's sha256
  18. function calculateProof(string document) constant returns (bytes32) {
  19. return sha256(document);
  20. }
  21. // check if a document has been notarized
  22. function checkDocument(string document) constant returns (bool) {
  23. var proof = calculateProof(document);
  24. return hasProof(proof);
  25. }
  26. // returns true if proof is stored
  27. function hasProof(bytes32 proof) constant returns (bool) {
  28. return proofs[proof];
  29. }
  30. }