Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. pragma solidity ^0.4.13;
  2.  
  3. /**
  4. * @title SafeMath
  5. * @dev Math operations with safety checks that throw on error
  6. */
  7. library SafeMath {
  8. function mul(uint256 a, uint256 b) internal constant returns (uint256) {
  9. uint256 c = a * b;
  10. assert(a == 0 || c / a == b);
  11. return c;
  12. }
  13.  
  14. function div(uint256 a, uint256 b) internal constant returns (uint256) {
  15. // assert(b > 0); // Solidity automatically throws when dividing by 0
  16. uint256 c = a / b;
  17. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  18. return c;
  19. }
  20.  
  21. function sub(uint256 a, uint256 b) internal constant returns (uint256) {
  22. assert(b <= a);
  23. return a - b;
  24. }
  25.  
  26. function add(uint256 a, uint256 b) internal constant returns (uint256) {
  27. uint256 c = a + b;
  28. assert(c >= a);
  29. return c;
  30. }
  31. }
  32.  
  33. //
  34. //
  35. //
  36. //
  37. //
  38. //
  39. //
  40. //
  41.  
  42. contract WTF2 {
  43.  
  44.  
  45. using SafeMath for uint256;
  46.  
  47. string public constant symbol = "WTF2";
  48. string public constant name = "WTF2 Coin";
  49. uint256 public constant decimals = 3;
  50.  
  51. uint256 _totalSupply = 1000000;
  52. uint256 _currentSupply = 0;
  53. uint256 public constant RATE = 200;
  54.  
  55. // Owner of this contract
  56. address public owner;
  57.  
  58.  
  59.  
  60. // Balances for each account
  61. mapping(address => uint256) balances;
  62. // Owner of account approves the transfer of an amount to another account
  63. mapping(address => mapping (address => uint256)) allowed;
  64. // Functions with this modifier can only be executed by the owner
  65. modifier onlyOwner() {
  66. require(msg.sender != owner);
  67. _;
  68. }
  69.  
  70. modifier onlyPayloadSize(uint256 size){
  71. assert(msg.data.length >= size + 4);
  72. _;
  73. }
  74.  
  75. function() payable{
  76. createTokens(msg.sender);
  77. }
  78.  
  79. // Constructor ////////////////////////////////////////////////////////////////
  80. function WTF2() {
  81. owner = msg.sender;
  82. balances[owner] = _totalSupply;
  83. }
  84.  
  85.  
  86. function createTokens(address addr) payable{
  87. //require a check on date values: fail if past end date
  88. require(msg.value > 0); //desire this to be 0.01 ETH min
  89.  
  90. uint256 tokens = msg.value/1 ether;
  91. tokens = tokens.mul(RATE).mul(1000);
  92. //do calculations to acount for 18 decimals for wei
  93. require(_currentSupply.add(tokens) <= _totalSupply); //assure payout wouldn't exceed max setting
  94.  
  95. balances[owner] = balances[owner].sub(tokens);
  96. balances[addr] = balances[addr].add(tokens);
  97. Transfer(owner, addr, tokens);
  98.  
  99. owner.transfer(msg.value);
  100. _currentSupply = _currentSupply.add(tokens);
  101. }
  102.  
  103. function totalSupply() constant returns (uint256 totalSupply) {
  104. return _totalSupply;
  105. }
  106.  
  107. // What is the balance of a particular account?
  108. function balanceOf(address _owner) constant returns (uint256 balance) {
  109. return balances[_owner];
  110. }
  111.  
  112. // Transfer the balance from owner's account to another account
  113. function transfer(address _to, uint256 _value) returns (bool success) {
  114. require(
  115. balances[msg.sender] >= _value
  116. && _value > 0
  117. );
  118. balances[msg.sender] = balances[msg.sender].sub(_value);
  119. balances[_to] = balances[_to].add(_value);
  120. Transfer(msg.sender, _to, _value);
  121. return true;
  122. }
  123.  
  124. // Send _value amount of tokens from address _from to address _to
  125. // The transferFrom method is used for a withdraw workflow, allowing contracts to send
  126. // tokens on your behalf, for example to "deposit" to a contract address and/or to charge
  127. // fees in sub-currencies; the command should fail unless the _from account has
  128. // deliberately authorized the sender of the message via some mechanism; we propose
  129. // these standardized APIs for approval:
  130. function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
  131. require(
  132. balances[_from] >= _value
  133. && allowed[_from][msg.sender] >= _value
  134. && _value > 0
  135. );
  136. balances[_from] = balances[_from].sub(_value);
  137. allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  138. balances[_to] = balances[_to].add(_value);
  139. Transfer(_from, _to, _value);
  140. return true;
  141. }
  142.  
  143. // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
  144. // If this function is called again it overwrites the current allowance with _value.
  145. function approve(address _spender, uint256 _value) returns (bool success) {
  146. allowed[msg.sender][_spender] = _value;
  147. Approval(msg.sender, _spender, _value);
  148. return true;
  149. }
  150.  
  151. function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  152. return allowed[_owner][_spender];
  153. }
  154.  
  155. event Transfer(address indexed _from, address indexed _to, uint _value);
  156. event Approval(address indexed _owner, address indexed _spender, uint _value);
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement