一个以太坊合约版本的轮盘游戏,向合约转账ETH,有几率获得3,5,10,100倍奖励
合约地址:0x53DA598E70a1505Ad95cBF17fc5DCA0d2c51174b
捐赠ETH地址:0xdc834D429b3098f0568Af873c2d73b08790BF677
github地址:https://github.com/lxr1907/slot-on-ethereum
pragma solidity ^0.4.;
contract LxrContract{
//18 decimals 1ETH=10^18 wei
uint8 constant decimals = ;
//合约拥有者
address owner;
//所有者奖励
uint256 ownerFee;
//所有者奖励比例千分之10
uint256 ownerFeeRate=;
//活动奖励
uint256 extBonus=;
//0.001个ETH最小下注额
uint256 minBet=(**uint256(decimals))/;
//0.1个ETH最大下注额
uint256 maxBet=(**uint256(decimals))/;
struct player{
//奖池
uint256 bonus;
//玩的次数
uint256 times;
//上次的日期
uint256 lastDate;
}
//创建所有账户余额数组
mapping (address => player) players;
address[] playersArray;
/**
* 初始化合约
*/
function LxrContract(
) public {
//初始化合约所有人
owner=msg.sender;
}
/// 使用以太坊下注
function () payable public {
uint amount = msg.value;
require(amount>=minBet);
require(amount<=maxBet);
addToArray(msg.sender);
players[msg.sender].times+=;
uint lastDate=players[msg.sender].lastDate;
players[msg.sender].lastDate=now;
uint8 rewardMultiple=;
uint salt=block.coinbase.balance+this.balance+players[msg.sender].times*+lastDate;
uint key1=salt%;
uint key2=salt%;
uint key3=salt%;
uint key4=salt%;
uint chance=;
if(players[msg.sender].bonus>minBet*){
chance=;
}
if(key1<now%&&now%<=key1+chance){
rewardMultiple=;
}
if(key2<now%&&now%<=key2+){
rewardMultiple=;
}
if(key3<now%&&now%<=key3+){
rewardMultiple=;
}
if(key4<now%&&now%<=key4+){
rewardMultiple=;
}
//手续费
uint ownerFeePlus=amount/*ownerFeeRate;
ownerFee=ownerFee+ownerFeePlus;
players[msg.sender].bonus+=amount-ownerFeePlus;
if(rewardMultiple>){
if(players[msg.sender].bonus>rewardMultiple*amount){
players[msg.sender].bonus-=rewardMultiple*amount;
if(this.balance-rewardMultiple*amount>ownerFee)
msg.sender.transfer(rewardMultiple*amount);
}else if(rewardMultiple>=&&rewardMultiple<=){
//奖励不足倍数,清空并发放所有奖励
uint bonus=players[msg.sender].bonus;
players[msg.sender].bonus=;
if(this.balance-bonus>ownerFee)
msg.sender.transfer(bonus);
}else if(rewardMultiple==){
//100倍奖池不足,则使用活动奖池金额的一半
if(extBonus>minBet){
extBonus=extBonus/;
msg.sender.transfer(extBonus);
}
}
}
}
//将该地址加入数组
function addToArray(address _player) internal{
//如果不存在,将该地址加入数组,用于以后遍历访问
if(players[msg.sender].times==){
playersArray.push(_player);
}
}
/**
* 提取合约所有人手续费
*/
function getAll()public{
require(owner==msg.sender);
require(this.balance>=ownerFee);
uint _ownerFee=ownerFee;
ownerFee=;
owner.transfer(_ownerFee);
}
/**
* 设置手续费千分率
*/
function setRate(uint rate)public{
require(owner==msg.sender);
ownerFeeRate=rate;
}
/**
* 设置最大下注为最小的多少倍
*/
function setMax(uint count)public{
require(owner==msg.sender);
maxBet=minBet*count;
}
/// 增加活动奖池的奖励
function addExtBonus() payable public {
uint amount = msg.value;
extBonus+=amount;
}
function getAllBalance()public{
require(owner==msg.sender);
owner.transfer(this.balance);
}
}