daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Jun 21st, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.22;
  2.  
  3. contract Example{
  4.  
  5. struct Institution {
  6.     bytes32 name;
  7.     bool exists;
  8. }
  9.  
  10. event AddedInstitution(bytes32 name);
  11.  
  12. mapping(bytes32 => Institution) institutions;
  13.  
  14. //add an institution
  15. function addInstitution(
  16.     bytes32 name,
  17.     bytes32 upi
  18. ) public {
  19.     require(!isInstitutionExists(upi));
  20.     institutions[upi].name = name;
  21.     institutions[upi].exists = true;
  22.     emit AddedInstitution(name);
  23.  
  24. }
  25. //get an institution
  26. function getInstitution(bytes32 upi) public constant returns (bytes32 name){
  27.     require(isInstitutionExists(upi));
  28.     return (
  29.     institutions[upi].name
  30.     );
  31.  
  32. }
  33. //is institution exist
  34. function isInstitutionExists(bytes32 upi) private constant returns (bool){
  35.     if (institutions[upi].exists) {
  36.         return true;
  37.     }
  38.     return false;
  39. }
  40.    
  41. '0x4d6f6920556e7669766572736974790000000000000000000000000000000000'
  42.    
  43. > web3.toAscii('0x4d6f6920556e7669766572736974790000000000000000000000000000000000')
  44. 'Moi Unviversity'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top