-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEvmosOdds.sol
More file actions
85 lines (70 loc) · 2.16 KB
/
EvmosOdds.sol
File metadata and controls
85 lines (70 loc) · 2.16 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
pragma solidity ^0.4.18;
contract EvmosOdds{
address public collector = 0xFb93CC2bF857b763909050B0D7816bC3b736E8DE; //Evmos testnet
uint8 public playerSpin;
uint256 public betAmount;
uint256 public winAmount;
uint256 public houseBalance;
uint80 constant None = uint80(0);
string public lastresult;
uint256 public lastWinAmount;
uint8 public lastPlayerSpin;
uint8 public lastOdds;
uint256 public maxBet = 10000000000000000;
uint8 public beforeS;
uint8 public afterS;
//Generate random number between 1 and 100
function Spin(address player) internal view returns (uint8) {
uint b = block.number;
uint timestamp = block.timestamp;
uint256 random = uint256(block.blockhash(b)) + uint256(player) + uint256(timestamp);
return uint8(random%100);
}
function play(uint8 house) public payable {
winAmount = (95 * msg.value) / house;
lastWinAmount = winAmount;
lastOdds = house;
if(winAmount > houseBalance){
msg.sender.transfer(msg.value);
}else{
betAmount = msg.value;
//playerSpin = Spin(msg.sender);
playerSpin = 5;
checkAndFundWinner(house);
lastPlayerSpin = playerSpin;
}
clean();
}
//Reset fields
function clean() private{
betAmount = 0;
winAmount = 0;
playerSpin = 0;
}
//Check if winner
function checkAndFundWinner(uint8 house) private{
if (playerSpin < house){
msg.sender.transfer(winAmount);
houseBalance -= (winAmount - msg.value);
lastresult = "Player Wins";
}else{
houseBalance += betAmount;
lastresult = "House Wins";
}
}
function() public payable{
houseBalance += msg.value;
}
//Withdraw funds
function collectFunds() public payable{
if(msg.sender == collector){
msg.sender.transfer(houseBalance);
houseBalance =0;
}
}
function changeMaxBet(uint256 newMaxBet) public payable{
if(msg.sender == collector){
maxBet = newMaxBet;
}
}
}