Guest User

Untitled

a guest
May 20th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. // AUSMO Token test 2
  2. pragma solidity ^0.4.16;
  3.  
  4. contract TokenERC20 {
  5. string public name;
  6. string public symbol;
  7. uint8 public decimals = 18;
  8. uint256 public totalSupply;
  9.  
  10. mapping (address => uint256) public balanceOf;
  11. mapping (address => mapping (address => uint256)) public allowance;
  12.  
  13. event Transfer(address indexed from, address indexed to, uint256 value);
  14.  
  15. event Burn(address indexed from, uint256 value);
  16.  
  17. /**
  18. * Initializes contract with initial supply tokens to the creator of the contract
  19. */
  20. function TokenERC20(
  21. uint256 initialSupply,
  22. string tokenName,
  23. string tokenSymbol
  24. ) public {
  25. totalSupply = initialSupply * 10 ** uint256(decimals);
  26. balanceOf[msg.sender] = totalSupply;
  27. name = tokenName;
  28. symbol = tokenSymbol;
  29. }
  30.  
  31. /**
  32. * Internal transfer, only can be called by this contract
  33. */
  34. function _transfer(address _from, address _to, uint _value) internal {
  35. // Prevent transfer to 0x0 address. Use burn() instead
  36. require(_to != 0x0);
  37. // Check if the sender has enough
  38. require(balanceOf[_from] >= _value);
  39. // Check for overflows
  40. require(balanceOf[_to] + _value > balanceOf[_to]);
  41. // Save this for an assertion in the future
  42. uint previousBalances = balanceOf[_from] + balanceOf[_to];
  43. // Subtract from the sender
  44. balanceOf[_from] -= _value;
  45. // Add the same to the recipient
  46. balanceOf[_to] += _value;
  47. Transfer(_from, _to, _value);
  48. // Asserts are used to use static analysis to find bugs in your code. They should never fail
  49. assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
  50. }
  51.  
  52. /**
  53. * Transfer tokens
  54. *
  55. * Send `_value` tokens to `_to` from your account
  56. *
  57. * @param _to The address of the recipient
  58. * @param _value the amount to send
  59. */
  60. function transfer(address _to, uint256 _value) public {
  61. _transfer(msg.sender, _to, _value);
  62. }
  63.  
  64. /**
  65. * Transfer tokens from other address
  66. *
  67. * Send `_value` tokens to `_to` in behalf of `_from`
  68. *
  69. * @param _from The address of the sender
  70. * @param _to The address of the recipient
  71. * @param _value the amount to send
  72. */
  73. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
  74. require(_value <= allowance[_from][msg.sender]); // Check allowance
  75. allowance[_from][msg.sender] -= _value;
  76. _transfer(_from, _to, _value);
  77. return true;
  78. }
  79.  
  80. /**
  81. * Set allowance for other address
  82. *
  83. * Allows `_spender` to spend no more than `_value` tokens in your behalf
  84. *
  85. * @param _spender The address authorized to spend
  86. * @param _value the max amount they can spend
  87. */
  88. function approve(address _spender, uint256 _value) public
  89. returns (bool success) {
  90. allowance[msg.sender][_spender] = _value;
  91. return true;
  92. }
  93.  
  94. /**
  95. * Set allowance for other address and notify
  96. *
  97. * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
  98. *
  99. * @param _spender The address authorized to spend
  100. * @param _value the max amount they can spend
  101. * @param _extraData some extra information to send to the approved contract
  102. */
  103. function approveAndCall(address _spender, uint256 _value, bytes _extraData)
  104. public
  105. returns (bool success) {
  106. tokenRecipient spender = tokenRecipient(_spender);
  107. if (approve(_spender, _value)) {
  108. spender.receiveApproval(msg.sender, _value, this, _extraData);
  109. return true;
  110. }
  111. }
  112.  
  113. /**
  114. * Destroy tokens
  115. *
  116. * Remove `_value` tokens from the system irreversibly
  117. *
  118. * @param _value the amount of money to burn
  119. */
  120. function burn(uint256 _value) public returns (bool success) {
  121. require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
  122. balanceOf[msg.sender] -= _value; // Subtract from the sender
  123. totalSupply -= _value; // Updates totalSupply
  124. Burn(msg.sender, _value);
  125. return true;
  126. }
  127.  
  128. /**
  129. * Destroy tokens from other account
  130. *
  131. * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
  132. *
  133. * @param _from the address of the sender
  134. * @param _value the amount of money to burn
  135. */
  136. function burnFrom(address _from, uint256 _value) public returns (bool success) {
  137. require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
  138. require(_value <= allowance[_from][msg.sender]); // Check allowance
  139. balanceOf[_from] -= _value; // Subtract from the targeted balance
  140. allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
  141. totalSupply -= _value; // Update totalSupply
  142. Burn(_from, _value);
  143. return true;
  144. }
  145. }
  146.  
  147. contract owned {
  148. address public owner;
  149.  
  150. function owned() public {
  151. owner = msg.sender;
  152. }
  153.  
  154. modifier onlyOwner {
  155. require(msg.sender == owner);
  156. _;
  157. }
  158.  
  159. function transferOwnership(address newOwner) onlyOwner public {
  160. owner = newOwner;
  161. }
  162. }
  163.  
  164. interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
  165.  
  166. contract BITToken is owned, TokenERC20 {
  167.  
  168. mapping (address => bool) public frozenAccount;
  169.  
  170. /* This generates a public event on the blockchain that will notify clients */
  171. event FrozenFunds(address target, bool frozen);
  172.  
  173. /* Initializes contract with initial supply tokens to the creator of the contract */
  174. function BITToken(
  175. uint256 initialSupply,
  176. string tokenName,
  177. string tokenSymbol
  178. ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
  179.  
  180. /* Internal transfer, only can be called by this contract */
  181. function _transfer(address _from, address _to, uint _value) internal {
  182. require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
  183. require (balanceOf[_from] > _value); // Check if the sender has enough
  184. require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
  185. require(!frozenAccount[_from]); // Check if sender is frozen
  186. require(!frozenAccount[_to]); // Check if recipient is frozen
  187. balanceOf[_from] -= _value; // Subtract from the sender
  188. balanceOf[_to] += _value; // Add the same to the recipient
  189. Transfer(_from, _to, _value);
  190. }
  191.  
  192. /// @notice Create `mintedAmount` tokens and send it to `target`
  193. /// @param target Address to receive the tokens
  194. /// @param mintedAmount the amount of tokens it will receive
  195. function mintToken(address target, uint256 mintedAmount) onlyOwner public {
  196. balanceOf[target] += mintedAmount;
  197. totalSupply += mintedAmount;
  198. Transfer(0, this, mintedAmount);
  199. Transfer(this, target, mintedAmount);
  200. }
  201.  
  202. /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
  203. /// @param target Address to be frozen
  204. /// @param freeze either to freeze it or not
  205. function freezeAccount(address target, bool freeze) onlyOwner public {
  206. frozenAccount[target] = freeze;
  207. FrozenFunds(target, freeze);
  208. }
  209.  
  210. /**
  211. * Fallback function
  212. *
  213. * Preventing someone to send ether to this contract
  214. */
  215. function () payable {
  216. require(false);
  217. }
  218. }
Add Comment
Please, Sign In to add comment