-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsearchkeybyhash.sol
33 lines (29 loc) · 1.05 KB
/
searchkeybyhash.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pragma solidity 0.5.12;
contract SearchKeyByHash
{
struct CertificadoAluno {
string cpf;
string codigoCurso;
string texto;
bool exists;
}
mapping(bytes32 => CertificadoAluno) public certificados;
function addCertificado(string memory _cpf, string memory _codigoCurso, string memory _texto)
public
returns (bytes32)
{
CertificadoAluno memory ca = CertificadoAluno(_cpf, _codigoCurso, _texto, true);
bytes32 hashCertificado = keccak256(abi.encodePacked(_cpf, _codigoCurso));
certificados[hashCertificado] = ca;
return hashCertificado;
}
function buscaCertificado(string memory _cpf, string memory _codigoCurso)
public
view
returns (string memory, string memory, string memory)
{
CertificadoAluno memory ca = certificados[keccak256(abi.encodePacked(_cpf, _codigoCurso))];
require(ca.exists, "Certificado nao existe com para esse CPF e codigo de curso");
return (ca.cpf, ca.codigoCurso, ca.texto);
}
}