-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuniversitycontract.sol
86 lines (53 loc) · 2.24 KB
/
universitycontract.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
//SPDX-License-Identifier: MIT;
pragma solidity ^0.8.2;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract UniversityContract is ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("NFTUniversityDegree", "NFTDegree") {
owner = msg.sender;
}
//stores addresses that have been whitelisted
mapping(address => bool) public whitelistedAddresses;
//stores name of the student
mapping (address => string) public studentName;
//stores the time when an address was added
mapping(string => uint) public timeAddressAdded;
//stores addresses of issued degrees
mapping(address => bool) public IssuedDegrees;
//stores a persons address to tokenURI it holds
mapping(address => string) public PersonToDegree;
//stores address of the deployer
address owner;
//stores number of whitelistd addresses
uint8 public numAddressesWhitelisted;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function addAddressToWhitelist(address _newAddress, string memory _name) public onlyOwner{
require(!whitelistedAddresses[_newAddress], "student already whitelisted");
//Adds the address to the mapping
whitelistedAddresses[_newAddress] = true;
//Adds name of the student
studentName[_newAddress] = _name;
// Adds the time when the name and address was added
timeAddressAdded[_name] = block.timestamp;
numAddressesWhitelisted += 1;
}
function issueDegree (address to ) onlyOwner public {
IssuedDegrees[to] = true;
require(whitelistedAddresses[to], "Address not whitelisted");
}
function claimDegree(string memory tokenURI) public returns (uint256){
require(IssuedDegrees[msg.sender], "Degree not yet issued");
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(msg.sender, newItemId);
_setTokenURI(newItemId, tokenURI);
PersonToDegree[msg.sender] = tokenURI;
IssuedDegrees[msg.sender] = false;
return newItemId;
}
}