Created
March 8, 2018 20:31
-
-
Save anonymous/9bd71a676e6f96f096b14a8afe6e368b 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=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
here is another update