sensi-certi / contracts / ceritificate.sol
ceritificate.sol
Raw
/**
 *Submitted for verification at mumbai.polygonscan.com on 2023-02-10
*/
// already deployed on mumbai testnet at 0x3b2462c7f04c54288887dfe6e2154278dd476a04
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.24;

contract Certificate {

    address private owner;
    mapping(string => bytes32) private certificateHash;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyowner {
        require(msg.sender==owner);
        _;
    }

    function addCertificate(
        string memory uid,
        string memory issuedTo,
        string memory issuer,
        string memory course,
        string memory issuedOn
    ) external onlyowner() {
        certificateHash[uid] = keccak256(abi.encodePacked(issuedTo, issuer, course, issuedOn));
    }

    function verifyCertificate(
        string memory uid,
        string memory issuedTo,
        string memory issuer,
        string memory course,
        string memory issuedOn
    ) external view returns (bool) {
        if( certificateHash[uid] ==  keccak256(abi.encodePacked(issuedTo, issuer, course, issuedOn)) )
            return true;
        else
            return false;
    }

    function addCertificateForAll(
        string[] memory uid,
        string[] memory issuedTo,
        string[] memory issuer,
        string[] memory course,
        string[] memory issuedOn
    ) external onlyowner() {
        for(uint16 i = 0 ; i < uid.length ; i++){
            certificateHash[uid[i]] = keccak256(abi.encodePacked(issuedTo[i], issuer[i], course[i], issuedOn[i]));
        }
    }
}