Created
June 19, 2019 01:27
-
-
Save ernestognw/f16f9a8c397d9bf317ad70c8c80617a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
// Este contrato garantiza propiedad sobre un contrato | |
// Puede ser reemplazado con el de open zeppelin | |
// https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol | |
contract Owned{ | |
address owner; | |
constructor() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require( | |
msg.sender == owner, | |
"You must be the owner." | |
); | |
_; | |
} | |
} | |
contract Certificate is Owned{ | |
// Variables | |
// Estructura de holder, con los datos que contiene cada certificado | |
struct Holder{ | |
string name; | |
uint level; | |
} | |
// Asignacion de direccion a holder de certificado | |
mapping (address => Holder) holders; | |
// Lista de las direcciones de los holders | |
address[] public holderAccts; | |
event HolderInfo( | |
string name, | |
uint level | |
); | |
// Modificadores | |
// Limita el numero de niveles que puede tener un holder | |
modifier checkLevel(uint _level){ | |
require( | |
_level <= 3, | |
"You input the wrong level." | |
); | |
_; | |
} | |
// Funciones | |
// Crear un certificado | |
function setHolder(address _address, string memory _name, uint _level) onlyOwner checkLevel(_level) public{ | |
holders[_address].name = _name; | |
holders[_address].level = _level; | |
holderAccts.push(_address); | |
emit HolderInfo(_name, _level); | |
} | |
// Obtener todas las direcciones de los certificados | |
function getHolders() view public returns(address[] memory) { | |
return holderAccts; | |
} | |
// Obtener un certificado por direccion del holder | |
function getHolder(address _address) view public returns(string memory, uint){ | |
return (holders[_address].name, holders[_address].level); | |
} | |
// Contar la cantidad de personas certificadas | |
function countHolders() view public returns(uint) { | |
return holderAccts.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment