-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPFSCidTimestampMapping.sol
58 lines (46 loc) · 1.46 KB
/
IPFSCidTimestampMapping.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
50
51
52
53
54
55
56
57
58
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
contract IPFSCidTimeInfoMapping is AccessControl {
struct TimeInfo {
uint256 timestamp;
uint256 blockNumber;
}
mapping(string => TimeInfo) public cidTimeInfoMapping;
event TimeInfoSaved(string cid);
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(MINTER_ROLE, msg.sender);
_setupRole(ADMIN_ROLE, msg.sender);
}
function mint(string memory cid) public onlyRole(MINTER_ROLE) {
require(
cidTimeInfoMapping[cid].timestamp == 0,
"The CID has been minted"
);
cidTimeInfoMapping[cid] = TimeInfo({
timestamp: block.timestamp,
blockNumber: block.number
});
emit TimeInfoSaved(cid);
}
function burn(string memory cid) public onlyRole(ADMIN_ROLE) {
delete cidTimeInfoMapping[cid];
}
function getCIDTimeInfo(string memory cid)
public
view
returns (uint256, uint256)
{
require(
cidTimeInfoMapping[cid].timestamp != 0,
"The CID has not been minted"
);
return (
cidTimeInfoMapping[cid].timestamp,
cidTimeInfoMapping[cid].blockNumber
);
}
}