Guest User

Untitled

a guest
Feb 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. pragma solidity ^0.4.18;
  2.  
  3. import "./ERC223Interface.sol";
  4. import "./ERC223ReceivingContract.sol";
  5. import "./SafeMath.sol";
  6. import "./TokenController.sol";
  7.  
  8.  
  9. /**
  10. * @title Implementation of the token contract following the ERC223 standard.
  11. * @author Pieter Noyens - <admin@pjotr.tech>
  12. */
  13. contract Token is ERC223Interface {
  14. using SafeMath for uint;
  15.  
  16. // Public variables of the token.
  17. uint public totalSupply;
  18. string public name;
  19. string public symbol;
  20. uint8 public decimals = 2;
  21. address public issuer;
  22.  
  23. address public managingWallet = 0xCC69987f75f79e7831607308530037fA8E67c266; // Manager wallet address.
  24.  
  25. mapping(address => uint) public balances; // List of user balances.
  26.  
  27. event Minted(uint amount);
  28. event Burned(uint amount, address indexed owningAddress);
  29.  
  30. /*
  31. * Modifiers
  32. */
  33. modifier onlyIssuer() {
  34. // Only issuing company is allowed to do this action.
  35. if (msg.sender != issuer) {
  36. revert();
  37. }
  38. _;
  39. }
  40.  
  41. modifier originatingFromManagingWallet () {
  42. // Action has to trace back to manager wallet.
  43. if (tx.origin != managingWallet) {
  44. revert();
  45. }
  46. _;
  47. }
  48.  
  49. // Constructor
  50. function Token(string _name,
  51. string _symbol) public originatingFromManagingWallet {
  52. totalSupply = 0;
  53. name = _name;
  54. symbol = _symbol;
  55. issuer = msg.sender;
  56. }
  57.  
  58. // Function to update the token issuer in order to extend functionality in the future.
  59. function updateTokenIssuer(address _newTokenIssuer) public originatingFromManagingWallet {
  60. issuer = _newTokenIssuer;
  61. }
  62.  
  63. // Minting
  64. function mint(uint _amount) public onlyIssuer {
  65. TokenController tc = TokenController(msg.sender);
  66. balances[tc.organizationAddress()] = balances[tc.organizationAddress()].add(_amount);
  67. totalSupply = totalSupply.add(_amount);
  68. Minted(_amount);
  69. }
  70.  
  71. // Burning
  72. function burn(uint _amount, address _owningAddress) public onlyIssuer {
  73. balances[_owningAddress] = balances[_owningAddress].sub(_amount);
  74. totalSupply = totalSupply.sub(_amount);
  75. Burned(_amount, _owningAddress);
  76. }
  77.  
  78. /**
  79. * @dev Transfer the specified amount of tokens to the specified address.
  80. * Invokes the `tokenFallback` function if the recipient is a contract.
  81. * The token transfer fails if the recipient is a contract
  82. * but does not implement the `tokenFallback` function
  83. * or the fallback function to receive funds.
  84. *
  85. * @param _to Receiver address.
  86. * @param _value Amount of tokens that will be transferred.
  87. * @param _data Transaction metadata.
  88. */
  89. function transfer(address _to, uint _value, bytes _data) public {
  90. // Standard function transfer similar to ERC20 transfer with no _data .
  91. // Added due to backwards compatibility reasons .
  92. uint codeLength;
  93.  
  94. assembly {
  95. // Retrieve the size of the code on target address, this needs assembly .
  96. codeLength := extcodesize(_to)
  97. }
  98.  
  99. balances[msg.sender] = balances[msg.sender].sub(_value);
  100. balances[_to] = balances[_to].add(_value);
  101. if ( codeLength > 0 ) {
  102. ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
  103. receiver.tokenFallback(msg.sender, _value, _data);
  104. }
  105. Transfer(msg.sender, _to, _value, _data);
  106. }
  107.  
  108. /**
  109. * @dev Transfer the specified amount of tokens to the specified address.
  110. * This function works the same with the previous one
  111. * but doesn't contain `_data` param.
  112. * Added due to backwards compatibility reasons.
  113. *
  114. * @param _to Receiver address.
  115. * @param _value Amount of tokens that will be transferred.
  116. */
  117. function transfer(address _to, uint _value) public {
  118. uint codeLength;
  119. bytes memory empty;
  120.  
  121. assembly {
  122. // Retrieve the size of the code on target address, this needs assembly .
  123. codeLength := extcodesize(_to)
  124. }
  125.  
  126. balances[msg.sender] = balances[msg.sender].sub(_value);
  127. balances[_to] = balances[_to].add(_value);
  128. if ( codeLength > 0 ) {
  129. ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
  130. receiver.tokenFallback(msg.sender, _value, empty);
  131. }
  132. Transfer(msg.sender, _to, _value, empty);
  133. }
  134.  
  135.  
  136. /**
  137. * @dev Returns balance of the `_owner`.
  138. *
  139. * @param _owner The address whose balance will be returned.
  140. * @return balance Balance of the `_owner`.
  141. */
  142. function balanceOf(address _owner) public constant returns (uint balance) {
  143. return balances[_owner];
  144. }
  145. }
Add Comment
Please, Sign In to add comment