Created
July 5, 2018 01:26
-
-
Save danielmme/9ce5606a73fc6b5ff4f71eeb6136e91e 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.18; | |
contract EmissaodeCertificados { | |
string public nomeCurso = "Física"; | |
string public nomeAluno = "Daniel M Medeiros"; | |
string public emailAluno = "medeiros.danielm@gmail.com"; | |
address public ProfessorResponsavel = 0xE2cA82616ef026ff45143705f63830F62Bf0aede; | |
address public Aluno = 0xd4fd25d18118336e95016d532dad4b23d1610a5f; | |
address public InstituicaoEmissora; | |
function AlterarEmail(string novoemailAluno) public returns(string){ | |
require(Aluno == msg.sender, 'somente o aluno pode alterar seu email'); | |
emailAluno = novoemailAluno; | |
return novoemailAluno; | |
} | |
function ValidarCertificado(address _ProfessorResponsavel) public returns(address){ | |
require(ProfessorResponsavel == _ProfessorResponsavel, 'somente um professor pode validar o certificado'); | |
return ProfessorResponsavel; | |
} | |
function AlterarDadosAluno(string novoemailAluno, string novonomeAluno, string novonomeCurso) public returns(string){ | |
require(InstituicaoEmissora == msg.sender, 'somente a instituição pode alterar os dados do certificados'); | |
emailAluno = novoemailAluno; | |
nomeAluno = novonomeAluno; | |
nomeCurso = novonomeCurso; | |
return novoemailAluno; | |
} | |
constructor(string _nomeAluno, string _emailAluno) public { | |
nomeAluno = _nomeAluno; | |
emailAluno = _emailAluno; | |
InstituicaoEmissora = msg.sender; | |
} | |
} |
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 ContratoQualquer { | |
// variável qualquer | |
string public valor; | |
// função qualquer | |
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.24; | |
import "github.com/OpenZeppelin/openzeppelin-solidiy/contracts/math/SafeMath.sol"; |
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 { | |
// [tipo] [visibilidade] [nome] = [valor] [opcional] | |
uint public numeroMatricula; | |
address public proprietario; | |
mapping (address => bool) public testemunhas; | |
function transferir(address novoProprietario) public returns(address) { | |
require(proprietario == msg.sender, 'somente o dono pode alterar o novoDono'); | |
proprietario = novoProprietario; | |
return novoProprietario; | |
} | |
function assinar() public { | |
testemunhas[msg.sender] = true; | |
} | |
constructor(uint _numeroMatricula, address _proprietario, mapping _testemunhas) public { | |
numeroMatricula = _numeroMatricula; | |
testemunhas = _testemunhas; | |
proprietario = msg.sender; | |
} | |
} |
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 FigurinhaDaCopa { | |
// [tipo] [visibilidade] [nome] = [valor] [opcional] | |
uint public idade = 10; | |
string public nomeJogador = "Neymar Jr"; | |
uint public numeroCamisa = 10; | |
string public selecao = "Brasil"; | |
address public dono; | |
modifier somenteIdadeMaior(uint novaIdade) { | |
require(novaIdade > idade, "Nova idade de ser maior do que idade atual."); | |
_ | |
} | |
function alterarIdade(uint novaIdade) public somente | |
function alterarDono(address novoDono) public returns(address){ | |
require(dono == msg.sender, 'somente o dono pode alterar o novoDono'); | |
dono = novoDono; | |
return novoDono; | |
} | |
constructor(string _nomeJogador, uint _numeroCamisa, string _selecao) public { | |
nomeJogador = _nomeJogador; | |
numeroCamisa = _numeroCamisa; | |
selecao = _selecao; | |
dono = msg.sender; | |
} | |
} |
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/JogoDavelhaAbstrato.sol"; | |
import "localhost/SafeMath.sol"; | |
contract JogoDaVelha is JogoDaVelhaAbstrato { | |
uint public valorInscricao = 4; | |
constructor (uint _valorInscricao) public { | |
require(_valorInscricao > 0); | |
valorInscricao = _valorInscricao; | |
} | |
modifier inscricaoAberta(address jogador1, address jogador2) { | |
require(msg.sender == jogador1 || msg.sender == jogador2,"Inscrição aberta;"); | |
_; | |
} | |
modifier pagouInscricao(uint valorInscricao) { | |
require(saldos[msg.sender] == 4,"Inscrição aberta;"); | |
_; | |
} | |
modifier jogadaValida(address jogador1, address jogador2) { | |
require(jogador1 || jogador2,"Inscrição aberta;"); | |
_; | |
} | |
modifier jogoComecado(address jogador1, address jogador2) { | |
require(jogador1 || jogador2,"Inscrição aberta;"); | |
_; | |
} | |
} |
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 | |
// FUNÇÕES | |
// Define o valor de inscrição do jogo | |
// 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) public; | |
// Verifica se o tabuleiro está totalmente preenchido | |
function verificarEmpate() public returns(bool); | |
// Verifia se o jogador atual ganhou | |
function verificarSeGanhou() public 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; | |
contract WonderlandCoin { | |
// VARIÁVEIS | |
string public nome = "WonderlandCoin"; | |
string public sigla = "WLC"; | |
mapping(address => uint) public saldos; | |
// MODIFIER | |
modifier temSaldo(uint valor) { | |
require(saldos[msg.sender] >= valor, "Não há saldo suficiente"); | |
_; | |
} | |
// FUNÇÕES | |
function transferir(uint valor, address para) temSaldo(valor) public { | |
saldos[msg.sender] -= valor; | |
saldos[para] += valor; | |
} | |
constructor(uint total) public { saldos[msg.sender] = total; } } |
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/openzeppelin-solidiy/contracts/token/StandardToken.sol"; | |
import "./ERC20Interface"; | |
contract WonderlandCoinERC20 is ERC20Interface { | |
string public symbol; | |
string public name; | |
uint8 public decimals; | |
uint public _totalSupply; | |
mapping(address => uint) balances; | |
mapping(address => mapping(address => uint)) allowed; | |
constructor () { | |
symbol = "MEU"; | |
name = "Meu primeiro token"; | |
decimals = 18; | |
_totalSupply = 1000000 * 10**uint(decimals); // 1.000.000 tokens com 18 | |
balances[msg.sender] = _totalSupply; // todos os tokens são de quem crio | |
emit Transfer(address(0), msg.sender, _totalSupply); | |
} | |
function totalSupply() returns (uint) { | |
return _totalSupply; | |
} | |
function balanceOf(address tokenOwner) constant returns (uint balance) { | |
return balances[tokenOwner]; | |
} | |
function transfer(address to, uint tokens) returns (bool success) { | |
balances[msg.sender] -= tokens; | |
balances[to] += tokens; | |
Transfer(msg.sender, to, tokens); | |
return true; | |
} | |
function approve(address spender, uint tokens) returns (bool success) { | |
allowed[msg.sender][spender] = tokens; | |
Approval(msg.sender, spender, tokens); | |
return true; | |
} | |
function transferFrom(address from, address to, uint tokens) returns (bool s | |
balances[from] -= tokens; | |
allowed[from][msg.sender] -= tokens; | |
balances[to] += tokens; | |
Transfer(from, to, tokens); | |
return true; | |
} | |
function allowance(address tokenOwner, address spender) returns (uint remain | |
return allowed[tokenOwner][spender]; | |
} | |
} |
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/openzeppelin-solidiy/contracts/ownership/Ownable.sol"; | |
import "github.com/OpenZeppelin/openzeppelin-solidiy/contracts/math/SafeMath.sol"; | |
contract CalculadoraSegura { | |
using SafeMath for uint; | |
function somar(uint a, uint b) returns(uint) { | |
return a.add(b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment