Last active
September 10, 2018 15:36
-
-
Save arkadiusss/e07de01575172de9322c8347240cae17 to your computer and use it in GitHub Desktop.
Token for article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | |
import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol"; | |
import "./ERC223.sol"; | |
import "./ERC223Receiver.sol"; | |
contract Token is StandardToken, ERC223 { | |
using SafeMath for uint256; | |
string public constant name = "Token"; | |
string public constant symbol = "T"; | |
uint8 public constant decimals = 18; | |
constructor(uint256 initialAmount) public { | |
balances[msg.sender] = initialAmount * 10**18; | |
totalSupply_ = initialAmount * 10**18; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(!isContract(_to)); | |
return super.transfer(_to, _value); | |
} | |
function transfer(address _to, uint256 _value, bytes32 _data) public returns (bool) { | |
require(_value <= balances[msg.sender]); | |
require(_to != address(0)); | |
require(_value > 0); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
if(isContract(_to)){ | |
ERC223Receiver receiver = ERC223Receiver(_to); | |
receiver.tokenFallback(msg.sender,_value,_data); | |
} | |
emit Transfer(msg.sender, _to, _value, _data); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool){ | |
require(!isContract(_to)); | |
return super.transferFrom(_from, _to, _value); | |
} | |
function isContract(address _to) private view returns (bool){ | |
uint codeLength; | |
assembly { | |
codeLength := extcodesize(_to) | |
} | |
return (codeLength > 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment