-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProofOfExistence.sol
45 lines (36 loc) · 974 Bytes
/
ProofOfExistence.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
contract ProofOfExistence {
event ProofCreated(uint256 indexed id, bytes32 documentHash);
address public owner;
mapping(uint256 => bytes32) hashesById;
modifier onlyOwner() {
require(
msg.sender == owner,
"Only the owner is allowed to access this function."
);
_;
}
modifier noHashExistsYet(uint256 id) {
require(hashesById[id] == "", "No hash exists for this id.");
_;
}
constructor() {
owner = msg.sender;
}
function notarizeHash(uint256 id, bytes32 documentHash)
public
onlyOwner
noHashExistsYet(id)
{
hashesById[id] = documentHash;
emit ProofCreated(id, documentHash);
}
function doesProofExist(uint256 id, bytes32 documentHash)
public
view
returns (bool)
{
return hashesById[id] == documentHash;
}
}