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; | |
} | |
} |
here is another update
pragma solidity 0.8.7;
contract Ownable {
address owner;
constructor() {
//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(payable(owner));
}
}
contract Casino is Mortal {
uint256 minBet;
uint256 houseEdge; //in %
event Won(bool _status, uint256 _amount);
constructor (uint256 _minBet, uint256 _houseEdge) payable {
require(_minBet > 0);
require(_houseEdge <= 100);
minBet = _minBet;
houseEdge = _houseEdge;
}
function bet(uint256 _number) public payable {
require(_number > 0 && _number <= 10, "Bet must be between 1 and 10");
require(msg.value >= minBet, "Bet must be bigger than minimum Bet");
uint256 winningNumber = (block.number % 10) + 1;
if (_number == winningNumber) {
uint256 amountWon = (msg.value * (100 - houseEdge)) / 10;
if (!payable(msg.sender).send(amountWon)) revert();
emit Won(true, amountWon);
} else {
emit Won(false, 0);
}
}
function checkContractBalance() public view Owned returns (uint256) {
return address(this).balance;
}
function checkMinBet() public view Owned returns (uint256) {
return minBet;
}
fallback() external payable {
//fallback
revert();
}
receive() external payable {
revert();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New smart contract to be up to date with solidity and remix: