Skip to content

Instantly share code, notes, and snippets.

@flyq
Created March 19, 2018 10:52
Show Gist options
  • Save flyq/bc44bf64b3047be5651d6b709d082e70 to your computer and use it in GitHub Desktop.
Save flyq/bc44bf64b3047be5651d6b709d082e70 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.20;
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract owned {
address public owner;
function owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
owner = newOwner;
}
}
contract biAnCrack is owned {
using SafeMath for uint256;
event AddBets(uint256 indexed kinds) ;
event Judge();
// 赌注只能是最小投注量的整数倍
uint256 private minBetUnit = 0.001 ether;
// 这里betBalanceOf[0]代表支持黑客赢这一方的赌注,包括黑客收到币安的钱或者黑客没收到币安的钱然后成功发动了入侵。
// 这里betBalanceOf[1]代表支持币安赢这一边的赌注,上述情况除外的都是属于币安赢的结果。
mapping (uint256 => uint256) private betBalanceOf;
// 某个地址在某个kinds上投注的个数
mapping (address => mapping (uint256 => uint256)) bets;
function biAnCrack() public {
betBalanceOf[0] = 0;
betBalanceOf[1] = 0;
}
function withdrawAll () onlyAdmins() public {
msg.sender.transfer(this.balance);
}
function withdrawAmount (uint256 _amount) onlyAdmins() public {
msg.sender.transfer(_amount);
}
// 旁人向某方加注,betsAmounts是最小投注量的个数
function addBet(uint256 kinds, uint256 betsAmounts) public payable{
require( (kinds == 0) || (kinds == 1));
betBalanceOf[kinds] += betsAmounts.mul(minBetUnit);
bets[msg.sender][kinds] = betsAmounts;
}
// 开奖,输入的kinds为0表示黑客赢了,为1表示币安赢了。。
function result(uint256 kinds){
uint256 all = betBalanceOf[0] + betBalanceOf[1];
// 合约抽成后剩余
all1 = all.mul(99).dev(100);
// 按比例分给获胜的一方。
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment