Created
May 6, 2022 23:51
-
-
Save jdmedeiros/35e6b2b6dd2bd6d55e81eba1f18410fa to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.7.0; | |
pragma abicoder v2; | |
contract PicarPonto { | |
struct Agente { | |
address sender; | |
string cargo; | |
string nome; | |
string data; | |
string hora1; | |
string hora2; | |
string hora3; | |
string hora4; | |
} | |
mapping(address => Agente) agente; | |
Agente[] registos; | |
constructor() { | |
autorizarAgente(0x6EA4bF97ed7557F13cA5289Ff6d7af01f9EaBaFb, "Formandor"); | |
autorizarAgente(0x829522f3Ca0421e9a16FE79f76BD5e12E4023a19, "Formando"); | |
} | |
function autorizarAgente(address oAgente, string memory oCargo) private { | |
agente[oAgente].sender = oAgente; | |
agente[oAgente].cargo = oCargo; | |
} | |
function marcar(string memory Nome, string memory Data, string memory Hora1, string memory Hora2, string memory Hora3, string memory Hora4) public { | |
require(agente[msg.sender].sender == msg.sender, unicode"Não está autorizado a intragir com este contrato."); | |
require(bytes(Nome).length > 0, unicode"É necessário inserir o seu nome."); | |
require(bytes(Data).length > 0, unicode"É necessário inserir a data."); | |
require(fOuP(Hora1), unicode"Deve usar exclusivamente P ou F para indicar presença ou falta."); | |
require(fOuP(Hora2), unicode"Deve usar exclusivamente P ou F para indicar presença ou falta."); | |
require(fOuP(Hora3), unicode"Deve usar exclusivamente P ou F para indicar presença ou falta."); | |
require(fOuP(Hora4), unicode"Deve usar exclusivamente P ou F para indicar presença ou falta."); | |
require(nova(Data), unicode"Já registou as presenças para esta data."); | |
agente[msg.sender].nome = Nome; | |
agente[msg.sender].data = Data; | |
agente[msg.sender].hora1 = Hora1; | |
agente[msg.sender].hora2 = Hora2; | |
agente[msg.sender].hora3 = Hora3; | |
agente[msg.sender].hora4 = Hora4; | |
registos.push(agente[msg.sender]); | |
} | |
function relatorio() public view returns (Agente[] memory) { | |
return registos; | |
} | |
function fOuP(string memory codigo) private pure returns (bool) { | |
if (keccak256(abi.encodePacked("P")) == keccak256(abi.encodePacked(codigo))) | |
return true; | |
if (keccak256(abi.encodePacked("F")) == keccak256(abi.encodePacked(codigo))) | |
return true; | |
return false; | |
} | |
function nova(string memory data) private view returns (bool) { | |
for (uint p = 0; p < registos.length; p++) { | |
if (registos[p].sender == msg.sender){ | |
if (keccak256(abi.encodePacked(registos[p].data)) == keccak256(abi.encodePacked(data))) | |
return false; | |
else | |
return true; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment