Skip to content

Instantly share code, notes, and snippets.

@valterlobo
Forked from Dione-b/CrudSimple.sol
Created February 8, 2023 12:14
Show Gist options
  • Save valterlobo/e9be0e2c23e778e50bc7e0e9850ab068 to your computer and use it in GitHub Desktop.
Save valterlobo/e9be0e2c23e778e50bc7e0e9850ab068 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract CrudSimples {
struct Pessoa {
string name;
uint8 idade;
uint id;
address owner;
}
event adicionarPessoa(uint id, string name);
uint count;
mapping(uint => Pessoa) pessoas;
constructor() {
count = 0;
}
// Adicionar pessoa
function addPessoa(string memory _name, uint8 _idade) public {
count += 1;
Pessoa memory pessoa = Pessoa(
_name,
_idade,
count,
msg.sender
);
pessoas[count] = pessoa;
emit adicionarPessoa(count, _name);
}
// Funções Getters & Setter para nome
function readPessoa(uint _id) public view returns (Pessoa memory){
return pessoas[_id];
}
function updateName(uint _id, string memory _name) public {
pessoas[_id].name = _name;
}
function updateIdade(uint _id, uint8 _idade) public {
pessoas[_id].idade = _idade;
}
function deletePessoa(uint _id) public {
delete pessoas[_id];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment