Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quillhash Challenge
pragma solidity ^0.4.0;
contract Lottery {
uint256 winner;
mapping(address => uint256) users;
address owner;
bool contractAccepting;
event value(uint256 value, address reee);
function Lottery(uint256 _winner){
winner = _winner;
owner = msg.sender;
contractAccepting = true;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function closeGame() onlyOwner {
contractAccepting = false;
}
function winnerAddress() constant returns(uint256){
return winner;
}
function getPrice() {
if(msg.sender == address(winner) && !contractAccepting){
msg.sender.send(this.balance / 2);
owner.send(this.balance / 2);
}
}
function makeGuess(uint256 _number){
if(users[msg.sender] > 0){
users[msg.sender] = users[msg.sender] - 1;
}else {
throw;
}
}
function() payable{
if(contractAccepting){
if(msg.value % 1 ether == 0){
users[msg.sender] += msg.value / 1 ether;
}else {
msg.sender.send(msg.value % 1 ether);
users[msg.sender] += msg.value / 1 ether;
}
value(this.balance, msg.sender);
value(msg.value, msg.sender);
value(users[msg.sender], msg.sender);
}else {
throw;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment