forked from ConsenSys-Academy/proof-of-existence-exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProofOfExistence3.sol
49 lines (42 loc) · 984 Bytes
/
ProofOfExistence3.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pragma solidity ^0.5.0;
contract ProofOfExistence3 {
mapping (bytes32 => bool) private proofs;
// store a proof of existence in the contract state
function storeProof(bytes32 proof)
internal
{
proofs[proof] = true;
}
// calculate and store the proof for a document
function notarize(string calldata document)
external
{
bytes32 proof = proofFor(document);
storeProof(proof);
}
// helper function to get a document's sha256
function proofFor(string memory document)
pure
public
returns (bytes32)
{
return keccak256(bytes(document));
}
// check if a document has been notarized
function checkDocument(string memory document)
public
view
returns (bool)
{
bytes32 proof = proofFor(document);
return hasProof(proof);
}
// returns true if proof is stored
function hasProof(bytes32 proof)
internal
view
returns(bool)
{
return proofs[proof];
}
}