Skip to content

Instantly share code, notes, and snippets.

@scalaview
Forked from anonymous/Casino.sol
Created March 15, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalaview/6f1bd30370640431c775a48c43217809 to your computer and use it in GitHub Desktop.
Save scalaview/6f1bd30370640431c775a48c43217809 to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.21+commit.dfe3193c.js&optimize=false&gist=
pragma solidity ^0.4.10;
contract Ownable {
address owner;
function Ownable() public {
owner = msg.sender;
}
modifier Owned {
require(msg.sender == owner);
_;
}
}
contract Mortal is Ownable {
function kill() public Owned {
selfdestruct(owner);
}
}
contract Casino is Mortal{
uint minBet;
uint houseEdge; //in %
event Won(bool _status, uint _amount);
function Casino(uint _minBet, uint _houseEdge) payable public {
require(_minBet > 0);
require(_houseEdge <= 100);
minBet = _minBet;
houseEdge = _houseEdge;
}
function() public { //fallback
revert();
}
function bet(uint _number) payable public {
require(_number > 0 && _number <= 10);
require(msg.value >= minBet);
uint winningNumber = block.number % 10 + 1;
if (_number == winningNumber) {
uint amountWon = msg.value * (100 - houseEdge)/10;
if(!msg.sender.send(amountWon)) revert();
emit Won(true, amountWon);
} else {
emit Won(false, 0);
}
}
function checkContractBalance() Owned public view returns(uint) {
address _contract = this;
return _contract.balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment