Created
March 3, 2019 04:07
-
-
Save eliooses/a931c9529768607459eb4b7873fb6040 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.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.5.1; | |
| import "browser/Ownership.sol"; | |
| contract Casino is Mortal { | |
| uint minBet; | |
| uint houseEdge; //in % | |
| //true+amount or false+0 | |
| event Won(bool _status, uint _amount); | |
| function CasinoF(uint _minBet, uint _houseEdge) payable public { | |
| require(_minBet > 0); | |
| require(_houseEdge <= 100); | |
| minBet = _minBet; | |
| houseEdge = _houseEdge; | |
| } | |
| function() external { //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) { | |
| return address(this).balance; | |
| } | |
| } |
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.5.1; | |
| contract Ownable { | |
| address payable owner; | |
| function OwnableF() public { | |
| //Set owner to who creates the contract | |
| owner = msg.sender; | |
| } | |
| //Access modifier | |
| modifier Owned { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| } | |
| contract Mortal is Ownable { | |
| //Our access modifier is present, only the contract creator can use this function | |
| function kill() public Owned { | |
| selfdestruct(owner); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment