Guest User

Untitled

a guest
Apr 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. pragma solidity ^0.4.21;
  2.  
  3. contract ERC20Interface {
  4.  
  5. function totalSupply() public constant returns (uint256);
  6. function balanceOf(address tokenOwner) public constant returns (uint256 balance);
  7. function allowance(address tokenOwner, address spender) public constant returns (uint256 remaining);
  8. function transfer(address to, uint256 tokens) public returns (bool success);
  9. function approve(address spender, uint256 tokens) public returns (bool success);
  10. function transferFrom(address from, address to, uint256 tokens) public returns (bool success);
  11.  
  12. event Transfer(address indexed from, address indexed to, uint tokens);
  13. event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
  14.  
  15. }
  16.  
  17. contract Owned {
  18.  
  19. address public owner;
  20. address public ownerCandidate;
  21.  
  22. function Owned() public {
  23. owner = msg.sender;
  24. }
  25.  
  26. modifier onlyOwner {
  27. require(msg.sender == owner);
  28. _;
  29. }
  30.  
  31. function changeOwner(address _newOwner) public onlyOwner {
  32. ownerCandidate = _newOwner;
  33. }
  34.  
  35. function acceptOwnership() public {
  36. require(msg.sender == ownerCandidate);
  37. owner = ownerCandidate;
  38. }
  39.  
  40. }
  41.  
  42. contract BLF_Lotto is Owned {
  43.  
  44. address public doublr_address = address(0x03358425ADa4620246dD703dC1F2246B8e148d22);
  45. address public powh3d_address = address(0xB3775fB83F7D12A36E0475aBdD1FCA35c091efBe);
  46.  
  47. DBLR doublr = DBLR(doublr_address);
  48. POWH weak_hands = POWH(powh3d_address);
  49.  
  50. bool public ready;
  51.  
  52. uint256 public minimum_pot;
  53. uint256 public ticket_price;
  54. uint256 public tickets_sold;
  55. uint256 public new_ticket_price;
  56.  
  57. mapping (uint256 => address) public tickets;
  58. mapping (address => uint256) public players;
  59.  
  60. event ticketPriceChange(
  61. uint256 new_price
  62. );
  63.  
  64. event potMinimumChange(
  65. uint256 new_min
  66. );
  67.  
  68. event lottoActivated(
  69. address winner,
  70. address referral_winner
  71. );
  72.  
  73. function BLF_Lotto() public {
  74. ready = false;
  75. minimum_pot = 1000000000000000000; // 1 Ether minimum before lotto is ready
  76. ticket_price = 10000000000000000; // 0.01 ETH
  77. new_ticket_price = ticket_price;
  78. }
  79.  
  80. modifier isReady() {
  81. require(ready == true);
  82. _;
  83. }
  84.  
  85. function getBalance() public view returns(uint256){
  86.  
  87. return address(this).balance;
  88.  
  89. }
  90.  
  91. function setMinimum(uint256 new_minimum) public onlyOwner {
  92.  
  93. require(new_minimum >= 1000000000000000000 && new_minimum <= 10000000000000000000); // 1 to 10 ETH
  94.  
  95. minimum_pot = new_minimum;
  96.  
  97. emit potMinimumChange(new_minimum);
  98.  
  99. }
  100.  
  101. function setTicketPrice(uint256 new_price) public onlyOwner { // Changes the ticket price for the next pot.
  102.  
  103. require(new_price >= 100000000000000 && new_price <= 10000000000000000); // 0.0001 to 0.01 ETH
  104.  
  105. new_ticket_price = new_price;
  106.  
  107. emit ticketPriceChange(new_price);
  108.  
  109. }
  110.  
  111. function buyTickets() public payable {
  112.  
  113. uint8 num_tickets;
  114.  
  115. if (msg.value >= 200000000000000000){
  116. num_tickets = 20;
  117. } else {
  118. num_tickets = SafeMath.div(msg.value, ticket_price);
  119. }
  120.  
  121. uint8 i = 0;
  122.  
  123. while (i < num_tickets){
  124.  
  125. i++;
  126.  
  127. tickets[tickets_sold] = msg.sender;
  128.  
  129. players[msg.sender]++;
  130.  
  131. tickets_sold++;
  132.  
  133. }
  134.  
  135. if (i == 20){ // return balance to sender
  136.  
  137. uint256 excess = SafeMath.sub(msg.value, 200000000000000000);
  138.  
  139. msg.sender.transfer(excess);
  140.  
  141. }
  142.  
  143. if (address(this).balance >= minimum_pot){
  144.  
  145. ready = true;
  146.  
  147. }
  148.  
  149. // uint256 divs = weak_hands.myDividends(true);
  150.  
  151. // if (divs > 10000000000000000){ // Withdraw if there is more than 0.01 ETH in divs.
  152. // weak_hands.withdraw();
  153. // }
  154.  
  155. }
  156.  
  157. function donateToPot() public payable {
  158.  
  159. // Adds to pot without buying tickets.
  160.  
  161. if (address(this).balance >= minimum_pot){
  162.  
  163. ready = true;
  164.  
  165. }
  166.  
  167. }
  168.  
  169. function() public payable {
  170. buyTickets();
  171. }
  172.  
  173. function execute() public isReady { // Anyone can activate the lottery once it is above the minimum balance
  174.  
  175. uint256 winner_share = SafeMath.div(address(this).balance, 2); // 50% to winner.
  176. uint256 doublr_share = SafeMath.div(address(this).balance, 3); // 33.3% to Doublr.
  177. uint256 powh3d_share = SafeMath.sub(winner_share, doublr_share); // 16.6% buys P3D.
  178.  
  179. uint256 winning_number = uint256(keccak256(block.blockhash(block.number - 1))) % tickets_sold; // Not true random, but doesn't really matter.
  180. uint256 referral_winner = uint256(keccak256(block.blockhash(block.number - 2))) % tickets_sold;
  181.  
  182. address winner = tickets[winning_number];
  183. address ref_winner = tickets[referral_winner];
  184.  
  185. winner.transfer(winner_share);
  186.  
  187. // doublr.transfer(doublr_share);
  188.  
  189. // weak_hands.buy.value(powh3d_share)(ref_winner);
  190.  
  191. ticket_price = new_ticket_price;
  192. tickets_sold = 0;
  193.  
  194. emit lottoActivated(winner, ref_winner);
  195.  
  196. }
  197.  
  198. function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
  199.  
  200. if (tokenAddress != powh3d){ // I can't steal the P3D tokens.
  201. return ERC20Interface(tokenAddress).transfer(owner, tokens); // THANKS!
  202. }
  203.  
  204. }
  205.  
  206. }
  207.  
  208. contract POWH {
  209.  
  210. function buy(address) public payable returns(uint256){}
  211. function withdraw() public {}
  212. function myDividends(bool) public view returns(uint256){}
  213.  
  214. }
  215.  
  216. contract DBLR {
  217.  
  218. function deposit() payable public {}
  219.  
  220. }
  221.  
  222. library SafeMath {
  223.  
  224. /**
  225. * @dev Multiplies two numbers, throws on overflow.
  226. */
  227. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  228. if (a == 0) {
  229. return 0;
  230. }
  231. uint256 c = a * b;
  232. assert(c / a == b);
  233. return c;
  234. }
  235.  
  236. /**
  237. * @dev Integer division of two numbers, truncating the quotient.
  238. */
  239. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  240. // assert(b > 0); // Solidity automatically throws when dividing by 0
  241. uint256 c = a / b;
  242. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  243. return c;
  244. }
  245.  
  246. /**
  247. * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  248. */
  249. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  250. assert(b <= a);
  251. return a - b;
  252. }
  253.  
  254. /**
  255. * @dev Adds two numbers, throws on overflow.
  256. */
  257. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  258. uint256 c = a + b;
  259. assert(c >= a);
  260. return c;
  261. }
  262.  
  263. }
Add Comment
Please, Sign In to add comment