Skip to content

Instantly share code, notes, and snippets.

@viannaandreBR
Created April 20, 2019 03:41
Show Gist options
  • Select an option

  • Save viannaandreBR/4664448cdbc34c151db78b3eff68ddad to your computer and use it in GitHub Desktop.

Select an option

Save viannaandreBR/4664448cdbc34c151db78b3eff68ddad 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=builtin&optimize=false&gist=
pragma solidity >=0.4.23;
// Versão Final Loteria / Solidity
contract Loteria {
address dono;
string nomeDoDono;
uint inicio;
struct Sorteio {
uint data;
uint numeroSorteado;
address remetente;
uint countPalpites;
}
Sorteio [] sorteios;
mapping (address => uint) palpites;
address [] palpiteiros;
address [] ganhadores;
constructor(string _nome) public {
dono = msg.sender;
nomeDoDono = _nome;
inicio = now;
}
modifier apenasDono() {
require (msg.sender == dono, "Apenas o dono do contrato pode fazer isso");
_;
}
modifier excetoDono(){
require (msg.sender != dono, "O dono do contrato não pode fazer isso");
_;
}
event TrocoEnviado(address pagante, uint troco);
event PalpiteRegistrado(address remetente, uint palpite);
function enviarPalpite(uint palpiteEnviado) payable public { //excetoDono(){
require (palpiteEnviado >= 1 && palpiteEnviado <=4, "Você tem que escolher um número entre 1 e 4");
require (palpites[msg.sender] == 0, "Apenas um palpite pode ser enviado por sorteio");
require (msg.value >= 1 ether, "A taxa para palpitar é 1 ether");
//Calcula e envia troco
uint troco = msg.value - 1 ether;
if (troco > 0){
msg.sender.transfer(troco);
emit TrocoEnviado(msg.sender, troco);
}
// registra o palpite
palpites[msg.sender] = palpiteEnviado;
palpiteiros.push(msg.sender);
emit PalpiteRegistrado(msg.sender, palpiteEnviado);
}
function verificarMeuPalpite() view public returns(uint palpite){
require (palpites[msg.sender] >0 , "Você não tem palpite ainda para esse sorteio");
return palpites[msg.sender];
}
function contarPalpites() view public returns(uint count){
return palpiteiros.length;
}
event SorteioPostado(uint resultado);
event PremiosEnviados(uint premioTotal, uint premioIndividual);
function sortear() public apenasDono() returns(uint8 _numeroSorteado) {
require (now > inicio + 1 minutes, "O sorteio só pode ser feito depois de um intervalo de 1 minuto");
require(palpiteiros.length >=1, "Um mínimo de 1 pessoa é exida para poder sortear");
// sortear um numeroSorteado
uint8 numeroSorteado = uint8(keccak256(abi.encodePacked(blockhash(block.number-1))))/64+1; //1
sorteios.push(Sorteio({
data:now,
numeroSorteado: numeroSorteado,
remetente: msg.sender,
countPalpites: palpiteiros.length
}));
emit SorteioPostado(numeroSorteado);
// procura os ganhadores
for (uint p=0; p<palpiteiros.length;p++){
address palpiteiro = palpiteiros[p];
if (palpites[palpiteiro] == numeroSorteado){
ganhadores.push(palpiteiro);
}
delete palpites[palpiteiro];
}
uint premioTotal = address(this).balance;
if (ganhadores.length > 0) {
uint premio = premioTotal / ganhadores.length;
// envia os premios
for (p=0; p<ganhadores.length; p++) {
ganhadores[p].transfer(premio);
}
emit PremiosEnviados(premioTotal, premio);
}
// resetar o Sorteio
delete palpiteiros;
delete ganhadores;
return numeroSorteado;
}
function kill () public apenasDono(){
dono.transfer(address(this).balance);
selfdestruct(dono);
}
}
pragma solidity ^0.4.0;
contract ArraySol {
address dono;
uint numeroSorteado;
uint contadorDeSorteios = 0;
uint [ ] numerosSorteados;
constructor (uint numeroInicial) public payable comCustoMinimo (1000) {
dono = msg.sender;
set(numeroInicial);
}
event TrocoEnviado(address pagador, uint troco);
function set(uint enviado) public payable comCustoMinimo(1000) {
numeroSorteado = enviado;
contadorDeSorteios++;
numerosSorteados.push(enviado);
if (msg.value > 1000){
uint troco = msg.value - 1000;
msg.sender.transfer(troco);
emit TrocoEnviado(msg.sender, troco);
}
}
modifier comCustoMinimo(uint min) {
require(msg.value >= min, "Nao foi enviado Ether suficiente.");
_;
}
function get() public view returns (
address _donoDoContrato,
uint _ultimoNumeroSorteado,
uint _contadorDeSorteios,
uint _saldoEmWei,
uint[] _todosNumerosSorteados)
{
uint ultimo = numerosSorteados[contadorDeSorteios-1];
return (dono,
ultimo,
contadorDeSorteios,
address(this).balance,
numerosSorteados
);
}
function kill() public {
require (msg.sender == dono);
selfdestruct(dono);
}
}
pragma solidity ^0.4.0;
contract GuardaLoteria {
address dono;
uint numeroSorteado;
uint contadorDeSorteios = 0;
uint[] numerosSorteados;
constructor(uint numeroInicial) public payable comCustoMinimo(1000) {
require (msg.sender.balance > 99.99999999999 ether);
dono = msg.sender;
set(numeroInicial);
}
event TrocoEnviado(address pagador, uint troco);
function set(uint enviado) public payable comCustoMinimo(1000) {
numeroSorteado = enviado;
contadorDeSorteios++;
numerosSorteados.push(enviado);
if (msg.value > 1000){
uint troco = msg.value - 1000;
msg.sender.transfer(troco);
emit TrocoEnviado(msg.sender, troco);
}
}
modifier comCustoMinimo(uint min) {
require(msg.value >= min, "Nao foi enviado Ether suficiente.");
_;
}
function get() public view returns (
address _donoDoContrato,
uint _ultimoNumeroSorteado,
uint _contadorDeSorteios,
uint _saldoEmWei,
uint[] _todosNumerosSorteados
) {
uint ultimo = numerosSorteados[contadorDeSorteios-1];
return (dono, ultimo, contadorDeSorteios, address(this).balance, numerosSorteados);
}
function kill () public {
require (msg.sender == dono);
selfdestruct(dono);
}
}
pragma solidity >=0.4.22 <0.6.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
uint voteCount;
}
address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;
/// Create a new ballot with $(_numProposals) different proposals.
constructor(uint8 _numProposals) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
proposals.length = _numProposals;
}
/// Give $(toVoter) the right to vote on this ballot.
/// May only be called by $(chairperson).
function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[toVoter].weight = 1;
}
/// Delegate your vote to the voter $(to).
function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
to = voters[to].delegate;
if (to == msg.sender) return;
sender.voted = true;
sender.delegate = to;
Voter storage delegateTo = voters[to];
if (delegateTo.voted)
proposals[delegateTo.vote].voteCount += sender.weight;
else
delegateTo.weight += sender.weight;
}
/// Give a single vote to proposal $(toProposal).
function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender];
if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true;
sender.vote = toProposal;
proposals[toProposal].voteCount += sender.weight;
}
function winningProposal() public view returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[prop].voteCount;
_winningProposal = prop;
}
}
}
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "./ballot.sol";
contract test3 {
Ballot ballotToTest;
function beforeAll () public {
ballotToTest = new Ballot(2);
}
function checkWinningProposal () public {
ballotToTest.vote(1);
Assert.equal(ballotToTest.winningProposal(), uint(1), "1 should be the winning proposal");
}
function checkWinninProposalWithReturnValue () public view returns (bool) {
return ballotToTest.winningProposal() == 1;
}
}
pragma solidity >=0.4.23;
contract Construtor {
uint numeroSorteado;
constructor(uint numeroInicial) public {
numeroSorteado = numeroInicial;
}
function set(uint enviado) public {
numeroSorteado = enviado;
}
function get() public view returns (uint){
return numeroSorteado;
}
}
pragma solidity >=0.4.23;
contract GuardaLoteria {
uint numeroSorteado;
address dono;
uint contadorDeSorteios = 0;
bool donoRico = false;
constructor (uint numeroInicial) public {
require (msg.sender.balance > 99.99999999999 ether);
numeroSorteado = numeroInicial;
dono = msg.sender;
contadorDeSorteios = 1;
if (msg.sender.balance > 20 ether){
donoRico = true;
}
else {
donoRico = false;
}
}
function set (uint enviado) public {
numeroSorteado = enviado;
contadorDeSorteios++;
dono = msg.sender;
}
function get() public view returns (uint) {
return numeroSorteado;
}
function getContador() public view returns(uint) {
return contadorDeSorteios;
}
function getDono() public view returns(address) {
return dono;
}
function getRico() public view returns(bool) {
return donoRico;
}
}
pragma solidity >=0.4.22 <0.6.0;
contract GuardaLoteria {
uint numeroSorteado;
function set(uint enviado) public {
numeroSorteado = enviado;
}
function get() public view returns (uint) {
return numeroSorteado;
}
}
pragma solidity >=0.4.22 <0.6.0;
contract GuardaLoteria1 {
uint numeroSorteado;
address dono;
uint contadorDeSorteios = 0;
bool donoRico = false;
constructor(uint numeroInicial) public{
require (msg.sender.balance > 99.99999999999 ether);
numeroSorteado = numeroInicial;
dono = msg.sender;
contadorDeSorteios = 1;
if (msg.sender.balance > 20 ether){
donoRico = true;
}
else {
donoRico = false;
}
}
function set(uint enviado) public {
numeroSorteado = enviado;
contadorDeSorteios++;
}
function get() public view returns (uint) {
return numeroSorteado;
}
function getContador() public view returns (uint){
return contadorDeSorteios;
}
function getDono() public view returns (address){
return dono;
}
function getRico() public view returns (bool){
return donoRico;
}
}
pragma solidity >=0.4.0;
contract GuardaLoteriaV3 {
uint numeroSorteado;
function set (uint enviado) public {
numeroSorteado = enviado;
}
function get() public view returns (uint){
return numeroSorteado;
}
}
pragma solidity ^0.4.23;
contract FlowOver {
uint16 numeroSorteado;
uint numeroSorteadoGrande;
uint16 contadorDeSorteios;
address dono;
constructor (uint16 numeroInicial) public {
numeroSorteado = numeroInicial; // 0 a 65535
contadorDeSorteios = 65530; // 0 a 2^256-1
dono = msg.sender;
}
function set(uint enviado) public payable {
numeroSorteadoGrande = enviado;
numeroSorteado = uint16(enviado);
require (msg.sender == dono , "Apenas o dono do contrato pode setar");
require ( contadorDeSorteios +1 > contadorDeSorteios , "Overflow no contador");
require ( numeroSorteado == numeroSorteadoGrande , "Overflow no numero");
contadorDeSorteios++;
}
function get() public view returns (uint _numero, uint _numeroSorteadoGrande, uint16 _contador, address _dono, address _contrato, uint _saldo) {
return (numeroSorteado,
numeroSorteadoGrande,
contadorDeSorteios,
dono,
this,
address(this).balance);
}
}
pragma solidity ^0.4.0;
contract Overflow {
uint16 numeroSorteado; // 0 a 65535
uint numeroSorteadoGrande; // 0 a 2^256 -1 ou (1.1579208923731619542357098500869e+77 – 1)
uint16 contadorDeSorteios;
address dono;
constructor(uint16 numeroInicial) public {
numeroSorteado = numeroInicial;
contadorDeSorteios = 65530;
dono = msg.sender;
}
function set(uint enviado) public payable {
numeroSorteadoGrande = enviado;
numeroSorteado = uint16(enviado);
require (msg.sender == dono, "apenas o dono do contrato pode setar");
require (contadorDeSorteios + 1 > contadorDeSorteios, "overflow no contador");
require (numeroSorteado == numeroSorteadoGrande, "overflow no numero");
contadorDeSorteios++;
}
function get() public view returns (uint _numero, uint _numeroSorteadoGrande, uint16 _contador, address _dono, address _contrato, uint _saldo) {
return (numeroSorteado,
numeroSorteadoGrande,
contadorDeSorteios,
dono,
this,
address(this).balance);
}
}
{
"accounts": {
"account{2}": "0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db",
"account{3}": "0x583031d1113ad414f02576bd6afabfb302140225",
"account{4}": "0xdd870fa1b7c4700f2bd7f44238821c26f7392148"
},
"linkReferences": {},
"transactions": [
{
"timestamp": 1555314485885,
"record": {
"value": "0",
"parameters": [
""
],
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"contractName": "Loteria",
"bytecode": "608060405234801561001057600080fd5b5060405161057538038061057583398101604052805160008054600160a060020a03191633600160a060020a0316179055018051610055906001906020840190610060565b5050426002556100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a157805160ff19168380011785556100ce565b828001600101855582156100ce579182015b828111156100ce5782518255916020019190600101906100b3565b506100da9291506100de565b5090565b6100f891905b808211156100da57600081556001016100e4565b90565b61046b8061010a6000396000f30060806040526004361061004b5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ad76c3108114610050578063aef43dce1461005d575b600080fd5b61005b600435610084565b005b34801561006957600080fd5b50610072610373565b60408051918252519081900360200190f35b600060018210158015610098575060048211155b1515610114576040805160e560020a62461bcd02815260206004820152602d60248201527f566f63c3aa2074656d20717565206573636f6c68657220756d206ec3ba6d657260448201527f6f20656e74726520312065203400000000000000000000000000000000000000606482015290519081900360840190fd5b73ffffffffffffffffffffffffffffffffffffffff3316600090815260046020526040902054156101b5576040805160e560020a62461bcd02815260206004820152602e60248201527f4170656e617320756d2070616c7069746520706f64652073657220656e76696160448201527f646f20706f7220736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b670de0b6b3a7640000341015610215576040805160e560020a62461bcd02815260206004820152601f60248201527f41207461786120706172612070616c706974617220c3a9203120657468657200604482015290519081900360640190fd5b50670de0b6b3a763ffff19340160008111156102c15760405173ffffffffffffffffffffffffffffffffffffffff33169082156108fc029083906000818181858888f1935050505015801561026e573d6000803e3d6000fd5b506040805173ffffffffffffffffffffffffffffffffffffffff331681526020810183905281517fb2f6b324486033af62b73731e627bef2c0b15dbfb1746f6beb433455e40cb091929181900390910190a15b73ffffffffffffffffffffffffffffffffffffffff331660008181526004602090815260408083208690556005805460018101825593527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0909201805473ffffffffffffffffffffffffffffffffffffffff1916841790558151928352820184905280517f18b14a53cd3a41d87ca1cf202539dadeb899df3db88d2adcbeae12628a32c4469281900390910190a15050565b73ffffffffffffffffffffffffffffffffffffffff33166000908152600460205260408120548110610415576040805160e560020a62461bcd02815260206004820152602e60248201527f566f63c3aa206ec3a36f2074656d2070616c706974652061696e64612070617260448201527f61206573736520736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b5073ffffffffffffffffffffffffffffffffffffffff3316600090815260046020526040902054905600a165627a7a7230582050d1415ea83cfae46361d97cb2a8c4c6633b36f6f9b671b46f8fc9d9413cd0d90029",
"linkReferences": {},
"name": "",
"inputs": "(string)",
"type": "constructor",
"from": "account{2}"
}
},
{
"timestamp": 1555314506177,
"record": {
"value": "20000000000000000000",
"parameters": [
"2"
],
"to": "created{1555314485885}",
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{2}"
}
},
{
"timestamp": 1555314785691,
"record": {
"value": "0",
"parameters": [
"3"
],
"to": "created{1555314485885}",
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{2}"
}
},
{
"timestamp": 1555314805358,
"record": {
"value": "2000000000000000000",
"parameters": [
"3"
],
"to": "created{1555314485885}",
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{3}"
}
},
{
"timestamp": 1555314925917,
"record": {
"value": "5000000000000000000",
"parameters": [
"4"
],
"to": "created{1555314485885}",
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{4}"
}
}
],
"abis": {
"0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec": [
{
"constant": false,
"inputs": [
{
"name": "palpiteEnviado",
"type": "uint256"
}
],
"name": "enviarPalpite",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"name": "_nome",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "pagante",
"type": "address"
},
{
"indexed": false,
"name": "troco",
"type": "uint256"
}
],
"name": "TrocoEnviado",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "remetente",
"type": "address"
},
{
"indexed": false,
"name": "palpite",
"type": "uint256"
}
],
"name": "PalpiteRegistrado",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "verificarMeuPalpite",
"outputs": [
{
"name": "palpite",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
}
}
{
"accounts": {
"account{0}": "0xca35b7d915458ef540ade6068dfe2f44e8fa733c",
"account{1}": "0x14723a09acff6d2a60dcdf7aa4aff308fddc160c"
},
"linkReferences": {},
"transactions": [
{
"timestamp": 1555334760386,
"record": {
"value": "0",
"parameters": [
""
],
"abi": "0xad315e209dd62516ab8c7d1c2d8c3c206525501ebef91d12c34431f9ea255371",
"contractName": "Loteria",
"bytecode": "608060405234801561001057600080fd5b5060405161092538038061092583398101604052805160008054600160a060020a03191633600160a060020a0316179055018051610055906001906020840190610060565b5050426002556100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a157805160ff19168380011785556100ce565b828001600101855582156100ce579182015b828111156100ce5782518255916020019190600101906100b3565b506100da9291506100de565b5090565b6100f891905b808211156100da57600081556001016100e4565b90565b61081b8061010a6000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416638ade2ac48114610066578063ad76c31014610091578063aef43dce1461009e578063fa8fce91146100c5575b600080fd5b34801561007257600080fd5b5061007b6100da565b6040805160ff9092168252519081900360200190f35b61009c60043561047c565b005b3480156100aa57600080fd5b506100b3610737565b60408051918252519081900360200190f35b3480156100d157600080fd5b506100b36107e9565b6000805481908190819033600160a060020a0390811691161461016d576040805160e560020a62461bcd02815260206004820152602960248201527f4170656e6173206f20646f6e6f20646f20636f6e747261746f20706f6465206660448201527f617a6572206973736f0000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600254603c0142116101ef576040805160e560020a62461bcd02815260206004820152603f60248201527f4f20736f727465696f2073c3b320706f64652073657220666569746f2064657060448201527f6f697320646520756d20696e74657276616c6f2064652031206d696e75746f00606482015290519081900360840190fd5b60055460011115610270576040805160e560020a62461bcd02815260206004820152603260248201527f556d206dc3ad6e696d6f206465203120706573736f6120c3a92065786964612060448201527f7061726120706f64657220736f72746561720000000000000000000000000000606482015290519081900360840190fd5b60408051600019430140602080830191909152825180830382018152918301808452825190918291908401908083835b602083106102bf5780518252601f1990920191602091820191016102a0565b5181516020939093036101000a6000190180199091169216919091179052604051920182900390912060ff16925050508115156102f857fe5b6040805160808101825242815292909104600190810160ff8116602080860182815233600160a060020a0390811688880190815260055460608a0190815260038054988901815560005298517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b60049098029788015591517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85c87015590517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85d8601805473ffffffffffffffffffffffffffffffffffffffff19169190921617905594517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85e90930192909255825191825291519195507f156a9da9fa9c030cd6aef7f9b1ae52e38066d0c3906f57547dfc1d1961ad43db92908290030190a1600091505b60055482101561047657600580548390811061045357fe5b60009182526020909120015460019290920191600160a060020a0316905061043b565b50505090565b600060018210158015610490575060048211155b151561050c576040805160e560020a62461bcd02815260206004820152602d60248201527f566f63c3aa2074656d20717565206573636f6c68657220756d206ec3ba6d657260448201527f6f20656e74726520312065203400000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a033316600090815260046020526040902054156105a0576040805160e560020a62461bcd02815260206004820152602e60248201527f4170656e617320756d2070616c7069746520706f64652073657220656e76696160448201527f646f20706f7220736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b670de0b6b3a7640000341015610600576040805160e560020a62461bcd02815260206004820152601f60248201527f41207461786120706172612070616c706974617220c3a9203120657468657200604482015290519081900360640190fd5b50670de0b6b3a763ffff193401600081111561069257604051600160a060020a0333169082156108fc029083906000818181858888f1935050505015801561064c573d6000803e3d6000fd5b5060408051600160a060020a03331681526020810183905281517fb2f6b324486033af62b73731e627bef2c0b15dbfb1746f6beb433455e40cb091929181900390910190a15b600160a060020a03331660008181526004602090815260408083208690556005805460018101825593527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0909201805473ffffffffffffffffffffffffffffffffffffffff1916841790558151928352820184905280517f18b14a53cd3a41d87ca1cf202539dadeb899df3db88d2adcbeae12628a32c4469281900390910190a15050565b600160a060020a03331660009081526004602052604081205481106107cc576040805160e560020a62461bcd02815260206004820152602e60248201527f566f63c3aa206ec3a36f2074656d2070616c706974652061696e64612070617260448201527f61206573736520736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b50600160a060020a03331660009081526004602052604090205490565b600554905600a165627a7a72305820bcbef6ca16f11428d21dbd2cb1519d9f7a0339d36f0937c8bfcdf15378acd0d90029",
"linkReferences": {},
"name": "",
"inputs": "(string)",
"type": "constructor",
"from": "account{0}"
}
},
{
"timestamp": 1555334832503,
"record": {
"value": "1000000000000000000",
"parameters": [
""
],
"abi": "0xad315e209dd62516ab8c7d1c2d8c3c206525501ebef91d12c34431f9ea255371",
"contractName": "Loteria",
"bytecode": "608060405234801561001057600080fd5b5060405161092538038061092583398101604052805160008054600160a060020a03191633600160a060020a0316179055018051610055906001906020840190610060565b5050426002556100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a157805160ff19168380011785556100ce565b828001600101855582156100ce579182015b828111156100ce5782518255916020019190600101906100b3565b506100da9291506100de565b5090565b6100f891905b808211156100da57600081556001016100e4565b90565b61081b8061010a6000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416638ade2ac48114610066578063ad76c31014610091578063aef43dce1461009e578063fa8fce91146100c5575b600080fd5b34801561007257600080fd5b5061007b6100da565b6040805160ff9092168252519081900360200190f35b61009c60043561047c565b005b3480156100aa57600080fd5b506100b3610737565b60408051918252519081900360200190f35b3480156100d157600080fd5b506100b36107e9565b6000805481908190819033600160a060020a0390811691161461016d576040805160e560020a62461bcd02815260206004820152602960248201527f4170656e6173206f20646f6e6f20646f20636f6e747261746f20706f6465206660448201527f617a6572206973736f0000000000000000000000000000000000000000000000606482015290519081900360840190fd5b600254603c0142116101ef576040805160e560020a62461bcd02815260206004820152603f60248201527f4f20736f727465696f2073c3b320706f64652073657220666569746f2064657060448201527f6f697320646520756d20696e74657276616c6f2064652031206d696e75746f00606482015290519081900360840190fd5b60055460011115610270576040805160e560020a62461bcd02815260206004820152603260248201527f556d206dc3ad6e696d6f206465203120706573736f6120c3a92065786964612060448201527f7061726120706f64657220736f72746561720000000000000000000000000000606482015290519081900360840190fd5b60408051600019430140602080830191909152825180830382018152918301808452825190918291908401908083835b602083106102bf5780518252601f1990920191602091820191016102a0565b5181516020939093036101000a6000190180199091169216919091179052604051920182900390912060ff16925050508115156102f857fe5b6040805160808101825242815292909104600190810160ff8116602080860182815233600160a060020a0390811688880190815260055460608a0190815260038054988901815560005298517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b60049098029788015591517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85c87015590517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85d8601805473ffffffffffffffffffffffffffffffffffffffff19169190921617905594517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85e90930192909255825191825291519195507f156a9da9fa9c030cd6aef7f9b1ae52e38066d0c3906f57547dfc1d1961ad43db92908290030190a1600091505b60055482101561047657600580548390811061045357fe5b60009182526020909120015460019290920191600160a060020a0316905061043b565b50505090565b600060018210158015610490575060048211155b151561050c576040805160e560020a62461bcd02815260206004820152602d60248201527f566f63c3aa2074656d20717565206573636f6c68657220756d206ec3ba6d657260448201527f6f20656e74726520312065203400000000000000000000000000000000000000606482015290519081900360840190fd5b600160a060020a033316600090815260046020526040902054156105a0576040805160e560020a62461bcd02815260206004820152602e60248201527f4170656e617320756d2070616c7069746520706f64652073657220656e76696160448201527f646f20706f7220736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b670de0b6b3a7640000341015610600576040805160e560020a62461bcd02815260206004820152601f60248201527f41207461786120706172612070616c706974617220c3a9203120657468657200604482015290519081900360640190fd5b50670de0b6b3a763ffff193401600081111561069257604051600160a060020a0333169082156108fc029083906000818181858888f1935050505015801561064c573d6000803e3d6000fd5b5060408051600160a060020a03331681526020810183905281517fb2f6b324486033af62b73731e627bef2c0b15dbfb1746f6beb433455e40cb091929181900390910190a15b600160a060020a03331660008181526004602090815260408083208690556005805460018101825593527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0909201805473ffffffffffffffffffffffffffffffffffffffff1916841790558151928352820184905280517f18b14a53cd3a41d87ca1cf202539dadeb899df3db88d2adcbeae12628a32c4469281900390910190a15050565b600160a060020a03331660009081526004602052604081205481106107cc576040805160e560020a62461bcd02815260206004820152602e60248201527f566f63c3aa206ec3a36f2074656d2070616c706974652061696e64612070617260448201527f61206573736520736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b50600160a060020a03331660009081526004602052604090205490565b600554905600a165627a7a72305820bcbef6ca16f11428d21dbd2cb1519d9f7a0339d36f0937c8bfcdf15378acd0d90029",
"linkReferences": {},
"name": "",
"inputs": "(string)",
"type": "constructor",
"from": "account{1}"
}
},
{
"timestamp": 1555334849970,
"record": {
"value": "0",
"parameters": [
"2"
],
"to": "created{1555334760386}",
"abi": "0xad315e209dd62516ab8c7d1c2d8c3c206525501ebef91d12c34431f9ea255371",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{1}"
}
},
{
"timestamp": 1555334886723,
"record": {
"value": "1000000000000000000",
"parameters": [
"3"
],
"to": "created{1555334760386}",
"abi": "0xad315e209dd62516ab8c7d1c2d8c3c206525501ebef91d12c34431f9ea255371",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{1}"
}
}
],
"abis": {
"0xad315e209dd62516ab8c7d1c2d8c3c206525501ebef91d12c34431f9ea255371": [
{
"constant": false,
"inputs": [
{
"name": "palpiteEnviado",
"type": "uint256"
}
],
"name": "enviarPalpite",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "sortear",
"outputs": [
{
"name": "_numeroSorteado",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_nome",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "pagante",
"type": "address"
},
{
"indexed": false,
"name": "troco",
"type": "uint256"
}
],
"name": "TrocoEnviado",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "remetente",
"type": "address"
},
{
"indexed": false,
"name": "palpite",
"type": "uint256"
}
],
"name": "PalpiteRegistrado",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "resultado",
"type": "uint256"
}
],
"name": "SorteioPostado",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "premioTotal",
"type": "uint256"
},
{
"indexed": false,
"name": "premioIndividual",
"type": "uint256"
}
],
"name": "PremiosEnviados",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "contarPalpites",
"outputs": [
{
"name": "count",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "verificarMeuPalpite",
"outputs": [
{
"name": "palpite",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
}
}
{
"accounts": {
"account{2}": "0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"
},
"linkReferences": {},
"transactions": [
{
"timestamp": 1555314485885,
"record": {
"value": "0",
"parameters": [
""
],
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"contractName": "Loteria",
"bytecode": "608060405234801561001057600080fd5b5060405161057538038061057583398101604052805160008054600160a060020a03191633600160a060020a0316179055018051610055906001906020840190610060565b5050426002556100fb565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a157805160ff19168380011785556100ce565b828001600101855582156100ce579182015b828111156100ce5782518255916020019190600101906100b3565b506100da9291506100de565b5090565b6100f891905b808211156100da57600081556001016100e4565b90565b61046b8061010a6000396000f30060806040526004361061004b5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ad76c3108114610050578063aef43dce1461005d575b600080fd5b61005b600435610084565b005b34801561006957600080fd5b50610072610373565b60408051918252519081900360200190f35b600060018210158015610098575060048211155b1515610114576040805160e560020a62461bcd02815260206004820152602d60248201527f566f63c3aa2074656d20717565206573636f6c68657220756d206ec3ba6d657260448201527f6f20656e74726520312065203400000000000000000000000000000000000000606482015290519081900360840190fd5b73ffffffffffffffffffffffffffffffffffffffff3316600090815260046020526040902054156101b5576040805160e560020a62461bcd02815260206004820152602e60248201527f4170656e617320756d2070616c7069746520706f64652073657220656e76696160448201527f646f20706f7220736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b670de0b6b3a7640000341015610215576040805160e560020a62461bcd02815260206004820152601f60248201527f41207461786120706172612070616c706974617220c3a9203120657468657200604482015290519081900360640190fd5b50670de0b6b3a763ffff19340160008111156102c15760405173ffffffffffffffffffffffffffffffffffffffff33169082156108fc029083906000818181858888f1935050505015801561026e573d6000803e3d6000fd5b506040805173ffffffffffffffffffffffffffffffffffffffff331681526020810183905281517fb2f6b324486033af62b73731e627bef2c0b15dbfb1746f6beb433455e40cb091929181900390910190a15b73ffffffffffffffffffffffffffffffffffffffff331660008181526004602090815260408083208690556005805460018101825593527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0909201805473ffffffffffffffffffffffffffffffffffffffff1916841790558151928352820184905280517f18b14a53cd3a41d87ca1cf202539dadeb899df3db88d2adcbeae12628a32c4469281900390910190a15050565b73ffffffffffffffffffffffffffffffffffffffff33166000908152600460205260408120548110610415576040805160e560020a62461bcd02815260206004820152602e60248201527f566f63c3aa206ec3a36f2074656d2070616c706974652061696e64612070617260448201527f61206573736520736f727465696f000000000000000000000000000000000000606482015290519081900360840190fd5b5073ffffffffffffffffffffffffffffffffffffffff3316600090815260046020526040902054905600a165627a7a7230582050d1415ea83cfae46361d97cb2a8c4c6633b36f6f9b671b46f8fc9d9413cd0d90029",
"linkReferences": {},
"name": "",
"inputs": "(string)",
"type": "constructor",
"from": "account{2}"
}
},
{
"timestamp": 1555314506177,
"record": {
"value": "20000000000000000000",
"parameters": [
"2"
],
"to": "created{1555314485885}",
"abi": "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec",
"name": "enviarPalpite",
"inputs": "(uint256)",
"type": "function",
"from": "account{2}"
}
}
],
"abis": {
"0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec": [
{
"constant": false,
"inputs": [
{
"name": "palpiteEnviado",
"type": "uint256"
}
],
"name": "enviarPalpite",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"name": "_nome",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "pagante",
"type": "address"
},
{
"indexed": false,
"name": "troco",
"type": "uint256"
}
],
"name": "TrocoEnviado",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "remetente",
"type": "address"
},
{
"indexed": false,
"name": "palpite",
"type": "uint256"
}
],
"name": "PalpiteRegistrado",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "verificarMeuPalpite",
"outputs": [
{
"name": "palpite",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
}
}
pragma solidity >=0.4.23;
contract StructSol {
address dono;
struct Sorteio {
uint data;
uint numeroSorteado;
address remetente;
}
Sorteio [] sorteios;
constructor(uint numeroInicial) public {
dono = msg.sender;
set(numeroInicial);
}
function set(uint enviado) public {
sorteios.push(Sorteio({
data: now,
numeroSorteado: enviado,
remetente: msg.sender
}));
}
function get() public view returns (
address _donoDoContrato,
uint _ultimoSorteado,
uint _ultimaData,
address _ultimoRemetente,
uint _numeroDeSorteios
){
Sorteio memory ultimo = sorteios[sorteios.length-1];
return(
dono,
ultimo.numeroSorteado,
ultimo.data,
ultimo.remetente,
sorteios.length
);
}
function kill() public {
require (msg.sender == dono);
selfdestruct(dono);
}
}
pragma solidity >= 0.4.0;
contract GuardaLoteria {
int8 numero;
bool numeroPar;
bool numeroImpar;
constructor(int256 _numero) public payable {
set (_numero);
}
function set(int256 _numero) public {
require (_numero == int8(_numero), "Valor não cabe na variável global");
numero = int8(_numero);
numeroPar = numero % 2 == 0;
numeroImpar = !numeroPar;
}
function get() public view returns (int8 _numero, bool _ePar, bool _eImpar) {
return (numero, numeroPar, numeroImpar);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment