Guest User

Untitled

a guest
May 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. pragma solidity ^0.4.19;
  2.  
  3. interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
  4.  
  5. contract TokenERC20 {
  6. // トークンの情報
  7. string public name = "ComCoin";
  8. string public symbol = "NCC";
  9. uint8 public decimals = 18;
  10. uint256 public totalSupply;
  11.  
  12. // This creates an array with all balances
  13. mapping (address => uint256) public balanceOf;
  14. mapping (address => mapping (address => uint256)) public allowance;
  15.  
  16. // This generates a public event on the blockchain that will notify clients
  17. event Transfer(address indexed from, address indexed to, uint256 value);
  18.  
  19. // This notifies clients about the amount burnt
  20. event Burn(address indexed from, uint256 value);
  21.  
  22. // コンストラクタ
  23. function TokenERC20(uint256 initialSupply) public {
  24. totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
  25. balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
  26. //name = tokenName; // Set the name for display purposes
  27. //symbol = tokenSymbol; // Set the symbol for display purposes
  28. }
  29.  
  30. /**
  31. * Internal transfer, only can be called by this contract
  32. */
  33. function _transfer(address _from, address _to, uint _value) internal {
  34. require(_to != 0x0); // 送金先がただしいかのチェック
  35. require(balanceOf[_from] >= _value); // 送金額よりたくさんお金を持っているか
  36. require(balanceOf[_to] + _value >= balanceOf[_to]); // オーバーフローしない
  37. // Save this for an assertion in the future
  38. uint previousBalances = balanceOf[_from] + balanceOf[_to];
  39. // Subtract from the sender
  40. balanceOf[_from] -= _value;
  41. // Add the same to the recipient
  42. balanceOf[_to] += _value;
  43. Transfer(_from, _to, _value);
  44. // Asserts are used to use static analysis to find bugs in your code. They should never fail
  45. assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
  46. }
  47.  
  48. /**
  49. * 送金する
  50. */
  51. function transfer(address _to, uint256 _value) public {
  52. _transfer(msg.sender, _to, _value);
  53. }
  54.  
  55. /**
  56. * Transfer tokens from other address
  57. *
  58. * Send `_value` tokens to `_to` on behalf of `_from`
  59. *
  60. * @param _from The address of the sender
  61. * @param _to The address of the recipient
  62. * @param _value the amount to send
  63. */
  64. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
  65. require(_value <= allowance[_from][msg.sender]); // Check allowance
  66. allowance[_from][msg.sender] -= _value;
  67. _transfer(_from, _to, _value);
  68. return true;
  69. }
  70.  
  71. /**
  72. * Set allowance for other address
  73. *
  74. * Allows `_spender` to spend no more than `_value` tokens on your behalf
  75. *
  76. * @param _spender The address authorized to spend
  77. * @param _value the max amount they can spend
  78. */
  79. function approve(address _spender, uint256 _value) public
  80. returns (bool success) {
  81. allowance[msg.sender][_spender] = _value;
  82. return true;
  83. }
  84.  
  85. /**
  86. * Set allowance for other address and notify
  87. *
  88. * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
  89. *
  90. * @param _spender The address authorized to spend
  91. * @param _value the max amount they can spend
  92. * @param _extraData some extra information to send to the approved contract
  93. */
  94. function approveAndCall(address _spender, uint256 _value, bytes _extraData)
  95. public
  96. returns (bool success) {
  97. tokenRecipient spender = tokenRecipient(_spender);
  98. if (approve(_spender, _value)) {
  99. spender.receiveApproval(msg.sender, _value, this, _extraData);
  100. return true;
  101. }
  102. }
  103.  
  104. /**
  105. * Destroy tokens
  106. *
  107. * Remove `_value` tokens from the system irreversibly
  108. *
  109. * @param _value the amount of money to burn
  110. */
  111. function burn(uint256 _value) public returns (bool success) {
  112. require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
  113. balanceOf[msg.sender] -= _value; // Subtract from the sender
  114. totalSupply -= _value; // Updates totalSupply
  115. Burn(msg.sender, _value);
  116. return true;
  117. }
  118.  
  119. /**
  120. * Destroy tokens from other account
  121. *
  122. * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
  123. *
  124. * @param _from the address of the sender
  125. * @param _value the amount of money to burn
  126. */
  127. function burnFrom(address _from, uint256 _value) public returns (bool success) {
  128. require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
  129. require(_value <= allowance[_from][msg.sender]); // Check allowance
  130. balanceOf[_from] -= _value; // Subtract from the targeted balance
  131. allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
  132. totalSupply -= _value; // Update totalSupply
  133. Burn(_from, _value);
  134. return true;
  135. }
  136. }
Add Comment
Please, Sign In to add comment