Created
July 5, 2018 01:34
-
-
Save andersoncarubelli/37f81ed3024b04bc35d662f65c4be0c9 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.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains 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
pragma solidity ^0.4.24; | |
import 'github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol'; | |
contract CalculadoraSegura { | |
using SafeMath for uint; | |
function somar(uint a, uint b) pure public returns(uint) { | |
return a.add(b); | |
} | |
function dividir(uint a, uint b) pure public returns(uint) { | |
return a.div(b); | |
} | |
function multiplicar(uint a, uint b) pure public returns(uint) { | |
a.mul(b); | |
} | |
function subtrair(uint a, uint b) pure public returns(uint) { | |
a.sub(b); | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
contract CertificadoConclusaoDeCurso { | |
address public aluno; | |
string public emailAluno; | |
address public professor; | |
address public instituicao; | |
string public nomeCurso; | |
bool public certificadoValido = false; | |
constructor(address _aluno, string _emailAluno, address _professor, string _nomeCurso, address _instituicao, bool _certificadoValido) public { | |
aluno = _aluno; | |
emailAluno = _emailAluno; | |
professor = _professor; | |
instituicao = _instituicao; | |
nomeCurso = _nomeCurso; | |
certificadoValido = _certificadoValido; | |
} | |
function defineProfessorAutorizado(address professorAutorizado) public { | |
require(msg.sender == instituicao, 'Somente a instituicao pode definir o professor que validar o certificado'); | |
professor = professorAutorizado; | |
} | |
function validarCertificado() public { | |
require(msg.sender == professor, 'Somente o professor pode validar o certificado'); | |
// check if the address is not set); | |
// obrigado stackoverflow ;) | |
require(professor != address(0), 'É necessario definir um professor para validar o certificado'); | |
certificadoValido = true; | |
} | |
function invalidarCertificado() public { | |
require(msg.sender == professor, 'Somente o professor pode validar o certificado'); | |
// check if the address is not set); | |
// obrigado stackoverflow ;) | |
require(professor != address(0), 'É necessario definir um professor para invalidar o certificado'); | |
certificadoValido = false; | |
} | |
function alterarEmailAluno(string novoEmail) public { | |
require(msg.sender == aluno, 'Somente o aluno pode alterar o email'); | |
emailAluno = novoEmail; | |
} | |
function alterarNomeCurso(string novoNomeCurso) public { | |
require(msg.sender == instituicao, 'Somente a instituicao pode alterar os dados do curso'); | |
nomeCurso = novoNomeCurso; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
contract ContratoQualquer { | |
string public valor; | |
function alterarValor(string novoValor) public { | |
valor = novoValor; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.18; | |
contract EscrituraImovel { | |
string public matriculaImovel; | |
address public proprietario; | |
mapping ( address => bool ) public testemunhas; | |
constructor(string _matriculaImovel) public { | |
matriculaImovel = _matriculaImovel; | |
proprietario = msg.sender; | |
} | |
function transferir(address novoProprietario) public { | |
require(msg.sender == proprietario, 'Somente o proprietario pode transferir o imovel'); | |
proprietario = novoProprietario; | |
} | |
function assinar() public { | |
testemunhas[msg.sender] = true; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
contract FigurinhaDaCopa { | |
string public nomeJogador = "Ronaldo gorducho"; | |
uint public numeroCamisa = 10; | |
string public selecao = "Brasil"; | |
address public dono; | |
constructor(string _nomeJogador, uint _numeroCamisa, string _selecao) public { | |
nomeJogador = _nomeJogador; | |
numeroCamisa = _numeroCamisa; | |
selecao = _selecao; | |
dono = msg.sender; | |
} | |
modifier somenteDono() { | |
require(msg.sender == dono, 'Somente o dono da figurinha pode alterar o novo dono'); | |
_; | |
} | |
function alterarDono(address novoDono) public somenteDono returns(address) { | |
dono = novoDono; | |
return dono; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
import './SafeMath.sol'; | |
import './JogoDaVelhaAbstrato.sol'; | |
contract JogoDaVelha is JogoDaVelhaAbstrato { | |
using SafeMath for uint; | |
constructor (uint _valorInscricao) public { | |
require(_valorInscricao > 0); | |
valorInscricao = _valorInscricao; | |
} | |
modifier inscricaoAberta() { | |
require(jogador1 != address(0) && jogador2 != address(0), 'A inscrição ainda está aberta!'); | |
_; | |
} | |
modifier pagouInscricao() { | |
require(msg.value == valorInscricao, 'Valor de inscrição inválido!'); | |
_; | |
} | |
modifier jogadaValida(uint _linha, uint _coluna) { | |
require(fimDoJogo == false); | |
require(msg.sender == jogadorDaVez); | |
require( (_linha >= 0 && _linha <= 2) || (_coluna >= 0 && _coluna <= 2), 'Jogada inválida!' ); | |
address jogada = tabuleiro[_linha][_coluna]; | |
require(jogada == address(0), 'Jogada já realizada'); | |
_; | |
} | |
modifier jogoComecado() { | |
require(jogador1 != address(0) && jogador2 != address(0), 'Jogo não iniciado!'); | |
_; | |
} | |
function inscrever() payable public inscricaoAberta pagouInscricao { | |
if (jogador1 == address(0)) { | |
jogador1 = msg.sender; | |
} | |
if (jogador2 == address(0)) { | |
jogador2 = msg.sender; | |
} | |
if (jogador1 != address(0) && jogador2 != address(0)) { | |
emit JogadorDaVez(jogador1); | |
emit ComecarJogo(); | |
} | |
} | |
function verificarEmpate() public returns(bool) { | |
return !verificarSeGanhou() && ( | |
// linha 0 | |
( tabuleiro[0][0] != 0x0 && tabuleiro[0][1] != 0x0 && tabuleiro[0][2] != 0x0 ) || | |
// linha 1 | |
( tabuleiro[1][0] != 0x0 && tabuleiro[1][1] != 0x0 && tabuleiro[1][2] != 0x0 ) || | |
// linha 2 | |
( tabuleiro[2][0] != 0x0 && tabuleiro[2][1] != 0x0 && tabuleiro[2][2] != 0x0 ) || | |
// coluna | |
( tabuleiro[0][0] != 0x0 && tabuleiro[1][0] !=0x0 && tabuleiro[2][0] != 0x0 ) || | |
// coluna 1 | |
( tabuleiro[0][1] != 0x0 && tabuleiro[1][1] != 0x0 && tabuleiro[2][1] != 0x0 ) || | |
// coluna 2 | |
( tabuleiro[0][2] != 0x0 && tabuleiro[1][2] != 0x0 && tabuleiro[2][2] != 0x0 ) || | |
// diagonal esquerda-cima, direita-baixo | |
( tabuleiro[0][0] != 0x0 && tabuleiro[1][1] != 0x0 && tabuleiro[2][2] != 0x0 ) || | |
// diagonal direita-cima, esquerda, baixo | |
( tabuleiro[0][2] != 0x0 && tabuleiro[1][1] != 0x0 && tabuleiro[2][0] != 0x0 ) | |
); | |
} | |
function jogar(uint linha, uint coluna) payable public jogoComecado jogadaValida(linha, coluna) { | |
require(msg.sender == jogadorDaVez, 'não é a sua vez!'); | |
tabuleiro[linha][coluna] = msg.sender; | |
if (verificarSeGanhou()) { | |
fimDoJogo = true; | |
jogadorDaVez.transfer(valorInscricao.mul(2)); | |
emit FimDeJogo(); | |
} else if (verificarEmpate()) { | |
fimDoJogo = true; | |
jogador1.transfer(valorInscricao); | |
jogador2.transfer(valorInscricao); | |
emit FimDeJogo(); | |
} else { | |
if (jogadorDaVez != jogador1) { | |
jogadorDaVez = jogador1; | |
} else { | |
jogadorDaVez = jogador2; | |
} | |
emit JogadorDaVez(jogadorDaVez); | |
} | |
} | |
function() payable public { | |
msg.sender.transfer(valorInscricao); | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
contract JogoDaVelhaAbstrato { | |
// VARIÁVEIS | |
address public jogador1; // endereço do jogador 1 | |
address public jogador2; // endereço do jogador 2 | |
address public jogadorDaVez; // endereço do jogador da vez | |
uint public valorInscricao; // valor da inscricao em wei | |
bool public fimDoJogo = false; // jogo terminou (empate ou ganhador) | |
mapping(uint => mapping(uint => address)) public tabuleiro; // tabuleiro[posicao_linha][posicao_coluna] = endereço_jogador | |
// Devolver dinheiro | |
function() payable public; | |
// Atribui msg.sender ao jogador 1 ou 2, define jogador da vez e emit ComecarJogo | |
function inscrever() payable public; | |
// Atribui valor no tabuleiro, verifica se o jogador ganhou ou houve empate e atualiza jogador da vez | |
// Se houve empate, devolver dinheiro para cada jogador | |
// Se o jogador da vez ganhou, transferir todo o dinheiro para devolver | |
// Emitir eventos quando necessário | |
function jogar(uint linha, uint coluna) payable public; | |
// Verifica se o tabuleiro está totalmente preenchido | |
function verificarEmpate() public returns(bool); | |
// Verifia se o jogador atual ganhou | |
function verificarSeGanhou() public view returns(bool) { | |
return ( | |
// linha 0 | |
( tabuleiro[0][0] == msg.sender && tabuleiro[0][1]==msg.sender && tabuleiro[0][2]==msg.sender ) || | |
// linha 1 | |
( tabuleiro[1][0] == msg.sender && tabuleiro[1][1]==msg.sender && tabuleiro[1][2]==msg.sender ) || | |
// linha 2 | |
( tabuleiro[2][0] == msg.sender && tabuleiro[2][1]==msg.sender && tabuleiro[2][2]==msg.sender ) || | |
// coluna 0 | |
( tabuleiro[0][0] == msg.sender && tabuleiro[1][0]==msg.sender && tabuleiro[2][0]==msg.sender ) || | |
// coluna 1 | |
( tabuleiro[0][1] == msg.sender && tabuleiro[1][1]==msg.sender && tabuleiro[2][1]==msg.sender ) || | |
// coluna 2 | |
( tabuleiro[0][2] == msg.sender && tabuleiro[1][2]==msg.sender && tabuleiro[2][2]==msg.sender ) || | |
// diagonal esquerda-cima, direita-baixo | |
( tabuleiro[0][0] == msg.sender && tabuleiro[1][1]==msg.sender && tabuleiro[2][2]==msg.sender ) || | |
// diagonal direita-cima, esquerda, baixo | |
( tabuleiro[0][2] == msg.sender && tabuleiro[1][1]==msg.sender && tabuleiro[2][0]==msg.sender ) | |
); | |
} | |
// EVENTOS | |
event ComecarJogo(); | |
event JogadorDaVez(address _jogadorDaVez); | |
event FimDeJogo(); | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the | |
// benefit is lost if 'b' is also tested. | |
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 | |
if (a == 0) { | |
return 0; | |
} | |
c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
// uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return a / b; | |
} | |
/** | |
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
import './WonderlandCoin.sol'; | |
contract WonderlandICO { | |
WonderlandCoin public token; | |
string moeda = "Wonderland Coin"; | |
address beneficiario; | |
uint public preco = 2; | |
uint public qtdTokens = 1000000000000; | |
constructor() public { | |
beneficiario = msg.sender; | |
token = new WonderlandCoin(qtdTokens); | |
token.transferir(msg.sender, 300000000000); | |
} | |
function comprar() payable public { | |
require(msg.value > 0, 'para comprar um token é preciso enviar ether'); | |
uint qtdTotalToken = msg.value * preco; | |
token.transferir(msg.sender, qtdTotalToken); | |
beneficiario.transfer(msg.value); | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
contract WonderlandCoin { | |
string nome = 'Wonderland Coin'; | |
string sigla = 'WLC'; | |
mapping (address => uint) public saldos; | |
constructor(uint valor) public{ | |
saldos[msg.sender] += valor; | |
} | |
modifier verificaSaldo(uint valor) { | |
require(saldos[msg.sender] >= valor, 'o saldo do sender deve ser maior ou igual ao valor transferido'); | |
_; | |
} | |
function transferir(address recebedor, uint valor) public verificaSaldo(valor) { | |
saldos[msg.sender] -= valor; | |
saldos[recebedor] += valor; | |
} | |
} |
This file contains 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
pragma solidity ^0.4.24; | |
import 'localhost/token/ERC20/StandardToken.sol'; | |
contract WonderlandCoinERC20 is StandardToken { | |
string public constant name = 'Wonderland Coin'; | |
string public constant symbol = 'WLC'; | |
uint8 public constant decimals = 18; | |
uint public totalSupply_; | |
constructor() public { | |
totalSupply_ = 10000 * (10 ** uint256(decimals)); | |
balances[msg.sender] = totalSupply_; | |
emit Transfer(0x0, msg.sender, totalSupply_); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment