Created
February 8, 2023 01:10
-
-
Save Dione-b/203d88d3fbdc826766037b754168c188 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
// 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