Guest User

Untitled

a guest
Jul 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. pragma solidity ^0.4.8;
  2.  
  3. /* ERC223 additions to ERC20 */
  4.  
  5. import "./interface/ERC223.sol";
  6. import "./interface/ERC223Receiver.sol";
  7.  
  8. import "./StandardToken.sol";
  9.  
  10. contract Standard223Token is ERC223, StandardToken {
  11. //function that is called when a user or another contract wants to transfer funds
  12. function transfer(address _to, uint _value, bytes _data) returns (bool success) {
  13. //filtering if the target is a contract with bytecode inside it
  14. if (!super.transfer(_to, _value)) throw; // do a normal token transfer
  15. if (isContract(_to)) return contractFallback(msg.sender, _to, _value, _data);
  16. return true;
  17. }
  18.  
  19. function transferFrom(address _from, address _to, uint _value, bytes _data) returns (bool success) {
  20. if (!super.transferFrom(_from, _to, _value)) revert(); // do a normal token transfer
  21. if (isContract(_to)) return contractFallback(_from, _to, _value, _data);
  22. return true;
  23. }
  24.  
  25. function transfer(address _to, uint _value) returns (bool success) {
  26. return transfer(_to, _value, new bytes(0));
  27. }
  28.  
  29. function transferFrom(address _from, address _to, uint _value) returns (bool success) {
  30. return transferFrom(_from, _to, _value, new bytes(0));
  31. }
  32.  
  33. //function that is called when transaction target is a contract
  34. function contractFallback(address _origin, address _to, uint _value, bytes _data) private returns (bool success) {
  35. ERC223Receiver reciever = ERC223Receiver(_to);
  36. return reciever.tokenFallback(msg.sender, _origin, _value, _data);
  37. }
  38.  
  39. //assemble the given address bytecode. If bytecode exists then the _addr is a contract.
  40. function isContract(address _addr) private returns (bool is_contract) {
  41. // retrieve the size of the code on target address, this needs assembly
  42. uint length;
  43. assembly { length := extcodesize(_addr) }
  44. return length > 0;
  45. }
  46. }
Add Comment
Please, Sign In to add comment