Skip to content
Verified contractPartial

Lotto

Address0x2c9775bbd244dc0591cf2b4df77407599ac9c59b
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.1.3

 

Same code

5 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
121,817
Creation transaction
0xba87326335…6f6389484d

Lotto.sol

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

    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;
        uint oldLength = rounds[roundIndex].buyers.length;
        rounds[roundIndex].buyers.length = rounds[roundIndex].buyers.length + ticketsCount;
        for (uint8 i = 0; i < ticketsCount; i++) rounds[roundIndex].buyers[oldLength + i] = msg.sender;
        rounds[roundIndex].pot += amount;
    }

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

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

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

    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].buyers.length;
        return rounds[roundIndex].buyers[winningTicketIndex];
    }

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

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

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

    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);
        winner.send(subpot);
        rounds[roundIndex].isCashed[subpotIndex] = true;
    }

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

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

    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.