Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. /**
  4. public - 안 밖에서 자유롭게 접근가능
  5. internal - 계약서 안에서 실행 가능한 함수를 통해서만 접근 가능
  6. external - 외부 계약서의 트랜잭션을 통해서만 접근 가능
  7. private - 계약서 내부일지라도 다른데서 상속받은 함수들이 아닌 순수 계약서만의 함수에서만 접근 가능
  8. */
  9.  
  10. contract tokenRecipient {
  11. function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external;
  12. }
  13.  
  14. contract RankingballToken {
  15. // Token 의 Public 변수 들
  16. string public standard = "Rankingball Token";
  17. string public name;
  18. string public symbol;
  19. uint8 public decimals;
  20. uint256 public totalSupply;
  21.  
  22. mapping (address => uint256) public balanceOf;
  23. mapping (address => mapping (address => uint256)) public allowance;
  24.  
  25. event Transfer(address indexed from, address indexed to, uint256 value);
  26. event Approved(address spender, uint value);
  27.  
  28. function RankingballToken (uint256 initialSupply, string tokenName, uint8 decimalUnits, string tokenSymbol) public {
  29. balanceOf[msg.sender] = initialSupply;
  30. totalSupply = initialSupply;
  31. name = tokenName;
  32. symbol = tokenSymbol;
  33. decimals = decimalUnits;
  34. }
  35.  
  36. /**
  37. * Token 이체, only can be called by this contract
  38. */
  39. function _transfer(address _from, address _to, uint256 _value) internal {
  40. //if (balanceOf[msg.sender] < _value) throw; // throw deprecated
  41. //if (balanceOf[_to] + _value < balanceOf[_to]) throw; // throw deprecated
  42.  
  43. // prevent transfer to 0x0 address. Use burn() instead
  44. require(_to != 0x0);
  45. // check if the sender has enough
  46. require(balanceOf[_from] >= _value);
  47. // check for overflows
  48. require(balanceOf[_to] + _value > balanceOf[_to]);
  49.  
  50. balanceOf[_from] -= _value;
  51. balanceOf[_to] += _value;
  52. emit Transfer(_from, _to, _value);
  53. }
  54.  
  55. /**
  56. * Transfer tokens
  57. *
  58. * Send `_value` tokens to `_to` from your account
  59. *
  60. * @param _to The address of the recipient
  61. * @param _value the amount to send
  62. */
  63. function transfer(address _to, uint256 _value) public {
  64. _transfer(msg.sender, _to, _value);
  65. }
  66.  
  67. /* 특정 Contract 가 내 대신 Token 을 쓸 수 있도록 함 */
  68. function approve(address _spender, uint256 _value) public returns (bool success_) {
  69. allowance[msg.sender][_spender] = _value;
  70. return true;
  71. }
  72.  
  73. /* Approve 받은 Contract 에게 알림 */
  74. function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success_) {
  75. tokenRecipient spender = tokenRecipient(_spender);
  76. if (approve(_spender, _value)) {
  77. spender.receiveApproval(msg.sender, _value, this, _extraData);
  78. emit Approved(_spender, _value);
  79. return true;
  80. }
  81. }
  82.  
  83. /**
  84. * Transfer tokens from other address
  85. *
  86. * Send `_value` tokens to `_to` in behalf of `_from`
  87. *
  88. * @param _from The address of the sender
  89. * @param _to The address of the recipient
  90. * @param _value the amount to send
  91. *
  92. * Contract 가 Token 을 가져가려 함
  93. */
  94. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success_) {
  95. //if (balanceOf[_from] < _value) throw;
  96. //if (balanceOf[_to] + _value < balanceOf[_to]) throw;
  97. //if (_value > allowance[_from][msg.sender]) throw;
  98. /*
  99. // check if the sender has enough
  100. require(balanceOf[_from] >= _value);
  101. // check for overflows
  102. require(balanceOf[_to] + _value > balanceOf[_to]);
  103. // check allowance
  104. require(_value <= allowance[_from][msg.sender]);
  105.  
  106. balanceOf[_from] -= _value;
  107. balanceOf[_to] += _value;
  108. allowance[_from][msg.sender] -= _value;
  109.  
  110. emit Transfer(_from, _to, _value);*/
  111.  
  112. // check allowance
  113. require(_value <= allowance[_from][msg.sender]);
  114. allowance[_from][msg.sender] -= _value;
  115. _transfer(_from, _to, _value);
  116.  
  117. return true;
  118. }
  119. }
Add Comment
Please, Sign In to add comment