Skip to content
Verified contractPartial

Lotto

Address0x4bf42d0ce494d62c3a7772fb4fd3881361d2e7e3
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.1.3

 

Same code

6 more contracts

 

Details

Compiler
solc 0.1.3+commit.028f561d
Language
solidity
Optimization
No
License
Not stated
Match
Partialcreation code: no, runtime code: yes
Verified on Sourcify
Created in block
156,304
Creation transaction
0x96512bb04a…e034eca265

Lotto.sol

// Recovered by EthereumHistory (ethereumhistory.com) -sw
contract Lotto {
    struct Round {
        address[] buyers;
        uint pot;
        uint ticketsCount;
        mapping (uint => bool) isCashed;
        mapping (address => uint) ticketsCountByBuyer;
    }

    mapping (uint => Round) rounds;

    function() {
        uint roundIndex = getRoundIndex();
        uint amount = msg.value - msg.value % 100000000000000000;
        if (amount == 0) return;
        if (amount < msg.value) msg.sender.send(msg.value - amount);
        uint ticketsCount = amount / 100000000000000000;
        if (rounds[roundIndex].ticketsCountByBuyer[msg.sender] == 0) {
            uint buyersLength = rounds[roundIndex].buyers.length++;
            rounds[roundIndex].buyers[buyersLength] = msg.sender;
        }
        rounds[roundIndex].ticketsCountByBuyer[msg.sender] += ticketsCount;
        rounds[roundIndex].ticketsCount += ticketsCount;
        rounds[roundIndex].pot += amount;
    }

    function getBlocksPerRound() returns (uint) {
        return 5760;
    }

    function getTicketPrice() returns (uint) {
        return 100000000000000000;
    }

    function getRoundIndex() returns (uint) {
        return block.number / 5760;
    }

    function getIsCashed(uint roundIndex, uint subpotIndex) returns (bool) {
        return rounds[roundIndex].isCashed[subpotIndex];
    }

    function calculateWinner(uint roundIndex, uint subpotIndex) returns (address) {
        uint decisionBlockNumber = getDecisionBlockNumber(roundIndex, subpotIndex);
        if (decisionBlockNumber > block.number) return;
        uint decisionBlockHash = getHashOfBlock(decisionBlockNumber);
        uint winningTicketIndex = decisionBlockHash % rounds[roundIndex].ticketsCount;
        uint ticketIndex = 0;
        for (uint8 buyerIndex = 0; buyerIndex < rounds[roundIndex].buyers.length; buyerIndex++) {
            address buyer = rounds[roundIndex].buyers[buyerIndex];
            ticketIndex += rounds[roundIndex].ticketsCountByBuyer[buyer];
            if (ticketIndex > winningTicketIndex) return buyer;
        }
    }

    function getDecisionBlockNumber(uint roundIndex, uint subpotIndex) returns (uint) {
        return (roundIndex + 1) * 5760 + subpotIndex;
    }

    function getSubpot(uint roundIndex) returns (uint) {
        return rounds[roundIndex].pot / getSubpotsCount(roundIndex);
    }

    function getSubpotsCount(uint roundIndex) returns (uint) {
        uint subpotsCount = rounds[roundIndex].pot / 5000000000000000000;
        if (rounds[roundIndex].pot % 5000000000000000000 > 0) subpotsCount++;
        return subpotsCount;
    }

    function cash(uint roundIndex, uint subpotIndex) {
        uint subpotsCount = getSubpotsCount(roundIndex);
        if (subpotIndex >= subpotsCount) return;
        uint decisionBlockNumber = getDecisionBlockNumber(roundIndex, subpotIndex);
        if (decisionBlockNumber > block.number) return;
        if (rounds[roundIndex].isCashed[subpotIndex]) return;
        address winner = calculateWinner(roundIndex, subpotIndex);
        uint subpot = getSubpot(roundIndex);
        bool sent = winner.send(subpot);
        if (!sent) return;
        rounds[roundIndex].isCashed[subpotIndex] = true;
    }

    function getHashOfBlock(uint blockIndex) returns (uint) {
        bytes32 blockHash = block.blockhash(blockIndex);
        return uint(blockHash);
    }

    function getBuyers(uint roundIndex, address buyer) returns (address[]) {
        return rounds[roundIndex].buyers;
    }

    function getTicketsCountByBuyer(uint roundIndex, address buyer) returns (uint) {
        return rounds[roundIndex].ticketsCountByBuyer[buyer];
    }

    function getPot(uint roundIndex) returns (uint) {
        return rounds[roundIndex].pot;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.