Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.18;
- import "./ERC223Interface.sol";
- import "./ERC223ReceivingContract.sol";
- import "./SafeMath.sol";
- import "./TokenController.sol";
- /**
- * @title Implementation of the token contract following the ERC223 standard.
- * @author Pieter Noyens - <admin@pjotr.tech>
- */
- contract Token is ERC223Interface {
- using SafeMath for uint;
- // Public variables of the token.
- uint public totalSupply;
- string public name;
- string public symbol;
- uint8 public decimals = 2;
- address public issuer;
- address public managingWallet = 0xCC69987f75f79e7831607308530037fA8E67c266; // Manager wallet address.
- mapping(address => uint) public balances; // List of user balances.
- event Minted(uint amount);
- event Burned(uint amount, address indexed owningAddress);
- /*
- * Modifiers
- */
- modifier onlyIssuer() {
- // Only issuing company is allowed to do this action.
- if (msg.sender != issuer) {
- revert();
- }
- _;
- }
- modifier originatingFromManagingWallet () {
- // Action has to trace back to manager wallet.
- if (tx.origin != managingWallet) {
- revert();
- }
- _;
- }
- // Constructor
- function Token(string _name,
- string _symbol) public originatingFromManagingWallet {
- totalSupply = 0;
- name = _name;
- symbol = _symbol;
- issuer = msg.sender;
- }
- // Function to update the token issuer in order to extend functionality in the future.
- function updateTokenIssuer(address _newTokenIssuer) public originatingFromManagingWallet {
- issuer = _newTokenIssuer;
- }
- // Minting
- function mint(uint _amount) public onlyIssuer {
- TokenController tc = TokenController(msg.sender);
- balances[tc.organizationAddress()] = balances[tc.organizationAddress()].add(_amount);
- totalSupply = totalSupply.add(_amount);
- Minted(_amount);
- }
- // Burning
- function burn(uint _amount, address _owningAddress) public onlyIssuer {
- balances[_owningAddress] = balances[_owningAddress].sub(_amount);
- totalSupply = totalSupply.sub(_amount);
- Burned(_amount, _owningAddress);
- }
- /**
- * @dev Transfer the specified amount of tokens to the specified address.
- * Invokes the `tokenFallback` function if the recipient is a contract.
- * The token transfer fails if the recipient is a contract
- * but does not implement the `tokenFallback` function
- * or the fallback function to receive funds.
- *
- * @param _to Receiver address.
- * @param _value Amount of tokens that will be transferred.
- * @param _data Transaction metadata.
- */
- function transfer(address _to, uint _value, bytes _data) public {
- // Standard function transfer similar to ERC20 transfer with no _data .
- // Added due to backwards compatibility reasons .
- uint codeLength;
- assembly {
- // Retrieve the size of the code on target address, this needs assembly .
- codeLength := extcodesize(_to)
- }
- balances[msg.sender] = balances[msg.sender].sub(_value);
- balances[_to] = balances[_to].add(_value);
- if ( codeLength > 0 ) {
- ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
- receiver.tokenFallback(msg.sender, _value, _data);
- }
- Transfer(msg.sender, _to, _value, _data);
- }
- /**
- * @dev Transfer the specified amount of tokens to the specified address.
- * This function works the same with the previous one
- * but doesn't contain `_data` param.
- * Added due to backwards compatibility reasons.
- *
- * @param _to Receiver address.
- * @param _value Amount of tokens that will be transferred.
- */
- function transfer(address _to, uint _value) public {
- uint codeLength;
- bytes memory empty;
- assembly {
- // Retrieve the size of the code on target address, this needs assembly .
- codeLength := extcodesize(_to)
- }
- balances[msg.sender] = balances[msg.sender].sub(_value);
- balances[_to] = balances[_to].add(_value);
- if ( codeLength > 0 ) {
- ERC223ReceivingContract receiver = ERC223ReceivingContract(_to);
- receiver.tokenFallback(msg.sender, _value, empty);
- }
- Transfer(msg.sender, _to, _value, empty);
- }
- /**
- * @dev Returns balance of the `_owner`.
- *
- * @param _owner The address whose balance will be returned.
- * @return balance Balance of the `_owner`.
- */
- function balanceOf(address _owner) public constant returns (uint balance) {
- return balances[_owner];
- }
- }
Add Comment
Please, Sign In to add comment