Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2018 20:22
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 anonymous/6b06bef626928589e3a53a70c021ec02 to your computer and use it in GitHub Desktop.
Save anonymous/6b06bef626928589e3a53a70c021ec02 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.20+commit.3155dd80.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();
Won(true, amountWon);
} else {
Won(false, 0);
}
}
function checkContractBalance() Owned public view returns(uint) {
return this.balance;
}
}
@zhengfen
Copy link

zhengfen commented Jun 17, 2019

pragma solidity ^0.5.0;

contract Ownable {
  address payable owner;
  // set the state variable ‘owner’ to the address of the creator.
  constructor() public {
    owner = msg.sender;
  }

  modifier Owned {
    require(msg.sender == owner);
    _;
  }
}

contract Mortal is Ownable {
  // allows the contract owner (access modifier) to destroy the contract and send the remaining funds back to him.
  function kill() public Owned {
    selfdestruct(owner);
  }
}

contract Casino is Mortal{
  uint minBet;
  uint houseEdge; //in %

  event Won(bool _status, uint _amount);

  // make our constructor payable so we can preload our contract with some Ether on deployment. 
  constructor(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;
  }
}

@cylonggit
Copy link

creation of Casino errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment