Skip to content

Instantly share code, notes, and snippets.

@gauravsaini03-zz
Created September 27, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauravsaini03-zz/ba7facff689720093493119c192d394c to your computer and use it in GitHub Desktop.
Save gauravsaini03-zz/ba7facff689720093493119c192d394c to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.4;
contract Certification {
address public certificateAuthority;
string public certificateAuthorityName;
mapping (bytes32 => bytes32) certificate; //sha3(register-number) => sha3(other info)
event Issued(bytes32 key);
function Certification(string _certificateAuthorityName) {
certificateAuthority = msg.sender;
certificateAuthorityName = _certificateAuthorityName;
}
//transactional functions
function issue(bytes32 _regNo, bytes32 _name) external {
require(msg.sender == certificateAuthority); //check authority
require(certificate[sha3(_regNo)] == 0 ); //check if already exists
bytes32 key = sha3(_regNo);
certificate[ key ] = sha3(_regNo, _name); //storage
Issued(key); //fire issued event
}
//constant functions
function verify(bytes32 _regNo, bytes32 _name) constant returns (bool) {
if( certificate[sha3(_regNo)] == sha3(_regNo, _name) ) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment