Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.21;
- contract ERC20Interface {
- function totalSupply() public constant returns (uint256);
- function balanceOf(address tokenOwner) public constant returns (uint256 balance);
- function allowance(address tokenOwner, address spender) public constant returns (uint256 remaining);
- function transfer(address to, uint256 tokens) public returns (bool success);
- function approve(address spender, uint256 tokens) public returns (bool success);
- function transferFrom(address from, address to, uint256 tokens) public returns (bool success);
- event Transfer(address indexed from, address indexed to, uint tokens);
- event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
- }
- contract Owned {
- address public owner;
- address public ownerCandidate;
- function Owned() public {
- owner = msg.sender;
- }
- modifier onlyOwner {
- require(msg.sender == owner);
- _;
- }
- function changeOwner(address _newOwner) public onlyOwner {
- ownerCandidate = _newOwner;
- }
- function acceptOwnership() public {
- require(msg.sender == ownerCandidate);
- owner = ownerCandidate;
- }
- }
- contract BLF_Lotto is Owned {
- address public doublr_address = address(0x03358425ADa4620246dD703dC1F2246B8e148d22);
- address public powh3d_address = address(0xB3775fB83F7D12A36E0475aBdD1FCA35c091efBe);
- DBLR doublr = DBLR(doublr_address);
- POWH weak_hands = POWH(powh3d_address);
- bool public ready;
- uint256 public minimum_pot;
- uint256 public ticket_price;
- uint256 public tickets_sold;
- uint256 public new_ticket_price;
- mapping (uint256 => address) public tickets;
- mapping (address => uint256) public players;
- event ticketPriceChange(
- uint256 new_price
- );
- event potMinimumChange(
- uint256 new_min
- );
- event lottoActivated(
- address winner,
- address referral_winner
- );
- function BLF_Lotto() public {
- ready = false;
- minimum_pot = 1000000000000000000; // 1 Ether minimum before lotto is ready
- ticket_price = 10000000000000000; // 0.01 ETH
- new_ticket_price = ticket_price;
- }
- modifier isReady() {
- require(ready == true);
- _;
- }
- function getBalance() public view returns(uint256){
- return address(this).balance;
- }
- function setMinimum(uint256 new_minimum) public onlyOwner {
- require(new_minimum >= 1000000000000000000 && new_minimum <= 10000000000000000000); // 1 to 10 ETH
- minimum_pot = new_minimum;
- emit potMinimumChange(new_minimum);
- }
- function setTicketPrice(uint256 new_price) public onlyOwner { // Changes the ticket price for the next pot.
- require(new_price >= 100000000000000 && new_price <= 10000000000000000); // 0.0001 to 0.01 ETH
- new_ticket_price = new_price;
- emit ticketPriceChange(new_price);
- }
- function buyTickets() public payable {
- uint8 num_tickets;
- if (msg.value >= 200000000000000000){
- num_tickets = 20;
- } else {
- num_tickets = SafeMath.div(msg.value, ticket_price);
- }
- uint8 i = 0;
- while (i < num_tickets){
- i++;
- tickets[tickets_sold] = msg.sender;
- players[msg.sender]++;
- tickets_sold++;
- }
- if (i == 20){ // return balance to sender
- uint256 excess = SafeMath.sub(msg.value, 200000000000000000);
- msg.sender.transfer(excess);
- }
- if (address(this).balance >= minimum_pot){
- ready = true;
- }
- // uint256 divs = weak_hands.myDividends(true);
- // if (divs > 10000000000000000){ // Withdraw if there is more than 0.01 ETH in divs.
- // weak_hands.withdraw();
- // }
- }
- function donateToPot() public payable {
- // Adds to pot without buying tickets.
- if (address(this).balance >= minimum_pot){
- ready = true;
- }
- }
- function() public payable {
- buyTickets();
- }
- function execute() public isReady { // Anyone can activate the lottery once it is above the minimum balance
- uint256 winner_share = SafeMath.div(address(this).balance, 2); // 50% to winner.
- uint256 doublr_share = SafeMath.div(address(this).balance, 3); // 33.3% to Doublr.
- uint256 powh3d_share = SafeMath.sub(winner_share, doublr_share); // 16.6% buys P3D.
- uint256 winning_number = uint256(keccak256(block.blockhash(block.number - 1))) % tickets_sold; // Not true random, but doesn't really matter.
- uint256 referral_winner = uint256(keccak256(block.blockhash(block.number - 2))) % tickets_sold;
- address winner = tickets[winning_number];
- address ref_winner = tickets[referral_winner];
- winner.transfer(winner_share);
- // doublr.transfer(doublr_share);
- // weak_hands.buy.value(powh3d_share)(ref_winner);
- ticket_price = new_ticket_price;
- tickets_sold = 0;
- emit lottoActivated(winner, ref_winner);
- }
- function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
- if (tokenAddress != powh3d){ // I can't steal the P3D tokens.
- return ERC20Interface(tokenAddress).transfer(owner, tokens); // THANKS!
- }
- }
- }
- contract POWH {
- function buy(address) public payable returns(uint256){}
- function withdraw() public {}
- function myDividends(bool) public view returns(uint256){}
- }
- contract DBLR {
- function deposit() payable public {}
- }
- 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;
- }
- }
Add Comment
Please, Sign In to add comment