Verified contractPartial
Lotto
Address0xdf415bb7ae2363ecbb6a595f07cbc2fc0fd417d3
- Balance
0 ETH
- Transactions
19
- Compiler
solc 0.1.3
- Same code
Only this contract
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
- 122,130
- Creation transaction
- 0x87c3f6224e…42c6019008
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 6800;
}
function getTicketPrice() returns (uint) {
return 100000000000000000;
}
function getRoundIndex() returns (uint) {
return block.number / 6800;
}
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) * 6800 + 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.