-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVCSoulBoundReceipt.sol
125 lines (107 loc) · 3.54 KB
/
VCSoulBoundReceipt.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
import "openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "openzeppelin-contracts/contracts/access/AccessControl.sol";
contract HealthRecordNFTReceipt is
ERC721,
ERC721URIStorage,
ERC721Burnable,
Ownable,
AccessControl
{
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
event NewRecord(address indexed owner, uint256 indexed tokenId);
event RecordDeleted(address indexed owner, uint256 indexed tokenId);
constructor() ERC721("HealthRecordNFTReceipt", "EHR") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
}
function safeMint(
address to,
uint256 tokenId,
string memory uri
) public onlyRole(MINTER_ROLE) {
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
// function to grant minting role to another address
function grantMinterRole(
address minter
) public onlyRole(DEFAULT_ADMIN_ROLE) {
_grantRole(MINTER_ROLE, minter);
}
// function to revoke minting role from an address
function revokeMinterRole(
address minter
) public onlyRole(DEFAULT_ADMIN_ROLE) {
_revokeRole(MINTER_ROLE, minter);
}
// function to grant admin role to another address
function grantAdminRole(address admin) public onlyRole(DEFAULT_ADMIN_ROLE) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
// function to revoke admin role from an address
function revokeAdminRole(
address admin
) public onlyRole(DEFAULT_ADMIN_ROLE) {
_revokeRole(DEFAULT_ADMIN_ROLE, admin);
}
function _beforeTokenTransfer(
address from,
address to
) internal virtual // uint256 tokenId
{
require(
from == address(0) || to == address(0),
"HealthRecordNFTReceipt: token is non-transferrable"
);
}
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {
if (from == address(0)) {
emit NewRecord(to, tokenId);
} else if (to == address(0)) {
emit RecordDeleted(from, tokenId);
}
}
// burn function only available to owner of token or admin
function burn(uint256 tokenId) public override {
require(
ownerOf(tokenId) == msg.sender ||
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
"HealthRecordNFTReceipt: caller is not the owner of token or has an admin role"
);
_burn(tokenId);
}
// deployer can revoke any token
function revoke(uint256 tokenId) external onlyOwner {
_burn(tokenId);
}
// The following functions are overrides required by Solidity.
function _burn(
uint256 tokenId
) internal override(ERC721, ERC721URIStorage) {
super._burn(tokenId);
}
function tokenURI(
uint256 tokenId
) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(tokenId);
}
function supportsInterface(
bytes4 interfaceId
)
public
view
override(ERC721, ERC721URIStorage, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}