-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetherDice.sol
33 lines (25 loc) · 888 Bytes
/
etherDice.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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(_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;
}
}