Skip to content

Instantly share code, notes, and snippets.

@iisaint
Last active January 4, 2019 02:25
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 iisaint/1b15c831aa6601e5d0b539c2e4f87f08 to your computer and use it in GitHub Desktop.
Save iisaint/1b15c831aa6601e5d0b539c2e4f87f08 to your computer and use it in GitHub Desktop.
pragma solidity >=0.4.22 <0.6.0;
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
contract EtherDice {
event LOG_RESULT(uint _number, uint _dice, address _winner);
constructor() public payable {
require(msg.value > 0.1 ether);
}
function roll() public view returns(uint) {
return (block.timestamp % 6);
}
function bet(uint _number) public payable returns(bool) {
require(isHuman(msg.sender), "robot is not allowed!!");
require(_number >=0 && _number <=5, "_number is between 0 to 5");
uint _dice = roll();
if (_number == _dice) {
msg.sender.transfer(msg.value*2);
emit LOG_RESULT(_number, _dice, msg.sender);
return true;
}
emit LOG_RESULT(_number, _dice, address(0x0));
return false;
}
function getPool() public view returns(uint) {
return address(this).balance;
}
function isHuman(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment