Skip to content

Instantly share code, notes, and snippets.

@falehenrique
Created December 16, 2017 10:37
Show Gist options
  • Save falehenrique/cf57ca1fc97008afbaaaa9402687e0e3 to your computer and use it in GitHub Desktop.
Save falehenrique/cf57ca1fc97008afbaaaa9402687e0e3 to your computer and use it in GitHub Desktop.
GO Dev 1 - Contratos Aula 16/12/2017
pragma solidity ^0.4.18;
//https://github.com/ethereum/EIPs/issues/223
contract ERC223Token {
string public name = "GoBlockchain Token";
uint8 public decimals = 0;
string public symbol = "GBC";
string public version = "GBC 1.0";
uint256 public totalSupply;
mapping(address => uint) balancesOf;
event LogAddTokenEvent(address indexed to, uint value);
event LogDestroyEvent(address indexed from, uint value);
event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);
function ERC223Token(uint256 _totalSupply) public {
totalSupply = _totalSupply;
balancesOf[msg.sender] = _totalSupply;
}
// Get the total token supply
function totalSupply() public constant returns (uint256 _supply){
return totalSupply;
}
/* Send coins */
function transfer(address _to, uint256 _value) public returns (bool ok){
require(balancesOf[msg.sender] >= _value);
balancesOf[msg.sender] -= _value;
balancesOf[_to] += _value;
return true;
}
function balanceOf(address who) public view returns (uint balance) {
return balancesOf[who];
}
function add(address _to, uint256 _value) public {
totalSupply += _value;
balancesOf[_to] += _value;
LogAddTokenEvent(_to, _value);
}
function destroy(address _from, uint256 _value) public {
totalSupply -= _value;
balancesOf[_from] -= _value;
LogDestroyEvent(_from, _value);
}
}
// prama informa a EVM a versão do solidity,
pragma solidity ^0.4.18;
contract Pessoa {
//variável do tipo string
string public nome;
string public email;
//eventos
event LogPersonEmailAlterado(address _pessoa, string emailAlterado);
// construtor
function Pessoa(string _nome, string _email) public {
nome = _nome;
email = _email;
}
// função com modificador
function mudarEmail(string _newMail) public {
email = _newMail;
}
}
// prama informa a EVM a versão do solidity,
pragma solidity ^0.4.18;
contract Solidity {
//variável do tipo string
string public nome;
string public email;
//variável do tipo int8, pode ir ate 256 bits
int8 public validacoesPositivas;
int8 public validacoesNegativas;
//variável do tipo address 20 bits - membros internos balance e transfer
//dono.balance e dono.transfer
address public dono;
// array de address
address[] public validacoes;
//variável do tipo struct
Documento public documento;
//variável do tipo mapping, armazena chave e valor
mapping(address => bool) public pessoaValidada;
//struct
// Define un nuevo tipo con dos campos.
struct Documento {
uint8 tipo;
bytes64 addressImage;
}
//bool, uint, bytes1....bytes32, uint128()
//eventos
event LogPersonEmailAlterado(address _pessoa, string emailAlterado);
// mofidicarod que é executado antes de entrar na função
//<=, <, ==, !=, >=, >
modifier apenasDono(){
require(msg.sender == dono)
_;
}
// construtor
function Pessoa(string _nome, string _email) public {
nome = _nome;
email = _email;
dono = msg.sender;
}
//function (<parameter types>) {internal|external|public|private} [constant{pure, view}] [modificador] [returns (<return types>)]
// função com modificador
function mudarEmail(string _newMail) public apenasDono {
email = _newMail;
}
// função com pure, não altera e não acessa nenhuma variável da classe
function nome() public view returns(string nome) {
return nome;
}
// função com pure, não altera e não acessa nenhuma variável da classe
function nome(string _email) public pure returns(bool emailValido) {
bytes memory emailBytes = bytes(_email);
if(emailBytes.length > 0) {
return true;
} else {
return false;
}
}
// função com pure, não altera e não acessa nenhuma variável da classe
function nomeEmail() public view returns(string nome, string email) {
return (nome, email);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment