-
Notifications
You must be signed in to change notification settings - Fork 0
/
CertificationContract.sol
36 lines (29 loc) · 1.34 KB
/
CertificationContract.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract CertificationContract {
struct Certification {
string name;
address recipient;
uint256 issueDate;
uint256 expirationDate;
bool isValid;
}
mapping(address => Certification[]) public certifications;
event CertificationIssued(address indexed recipient, string name, uint256 issueDate, uint256 expirationDate);
function issueCertification(address _recipient, string memory _name, uint256 _expirationDate) public {
Certification memory certification = Certification({
name: _name,
recipient: _recipient,
issueDate: block.timestamp,
expirationDate: _expirationDate,
isValid: true
});
certifications[_recipient].push(certification);
emit CertificationIssued(_recipient, _name, block.timestamp, _expirationDate);
}
function verifyCertification(address _recipient, uint256 _index) public view returns (bool) {
require(_index < certifications[_recipient].length, "Invalid certification index");
Certification memory certification = certifications[_recipient][_index];
return certification.isValid && certification.expirationDate >= block.timestamp;
}
}