pragma solidity ^0.4.23; contract Lottery { /* Initializes a list of addresses and ticket numbers for them, keeps track of last ticket number, when the timer goes off thru oraclize it gets a random number and finds the address which contains the ticket no, releases 90% funds to it and sends 10% to house Reinitializes state, sets new timer */ mapping(address => uint[]) tickets; address[] addresses; uint last_ticket_number; function() external payable { //see if this address exists in addresses, if yes, //assign more tickets to it, if not, create a new key //assign tickets //check if address already deposited for(uint i=0; i < addresses.length; i++) { if(addresses[i] == msg.sender) { revert(); //TODO: replace with adding to the list of tickets } } addresses.push(msg.sender); tickets[msg.sender] = create_tickets_array(msg.value); //send deposit event } function payout() external { //get random number through oracle, find address who has //the ticket with this number, reward them with 90% of contract balance //send winner notification through events //empty the tickets map and addresses array uint random_number = 8; //TODO: replace with random number from oraclize //loop through addresses for(uint i=0;i < addresses.length; i++) { if(tickets[addresses[i]].length > 0) { //loop over the array for(uint j = 0; j < tickets[addresses[i]].length; ++j) { if(tickets[addresses[i]][j] == random_number) { //DING DING! send 90% of contract balance to him //send 10% to us //send a "won" event and put him in the dashboard } else { //not the winner, pass } } } else { //doesn't even exist, should not happen, throw exception } } } function create_tickets_array(uint amount) internal { //return an array of numbers from last ticket number + amount } }
0.4.18