Created
April 16, 2017 16:30
-
-
Save goodjoon/9f90a87ac170bf549849367ae2cbaa3b to your computer and use it in GitHub Desktop.
[HYUNDAI] HYUNDAI TOKEN V2
This file contains hidden or 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.2; | |
| contract tokenReceipient { | |
| function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); | |
| } | |
| contract HyundaiToken { | |
| // Token 의 Public 변수 들 | |
| string public standard = "Hyundai Token"; | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals; | |
| uint256 public totalSupply; | |
| mapping (address => uint256) public balanceOf; | |
| mapping (address => mapping (address => uint256)) public allowance; | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| event Approved(address spender, uint value); | |
| function HyundaiToken ( | |
| uint256 initialSupply, | |
| string tokenName, | |
| uint8 decimalUnits, | |
| string tokenSymbol) { | |
| balanceOf[msg.sender] = initialSupply; | |
| totalSupply = initialSupply; | |
| name = tokenName; | |
| symbol = tokenSymbol; | |
| decimals = decimalUnits; | |
| } | |
| /* Token 이체 */ | |
| function transfer(address _to, uint256 _value) { | |
| if (balanceOf[msg.sender] < _value) throw; | |
| if (balanceOf[_to] + _value < balanceOf[_to]) throw; | |
| balanceOf[msg.sender] -= _value; | |
| balanceOf[_to] += _value; | |
| Transfer(msg.sender, _to, _value); | |
| } | |
| /* 특정 Contract 가 내 대신 Token 을 쓸 수 있도록 함 */ | |
| function approve(address _spender, uint256 _value) returns (bool success_) { | |
| allowance[msg.sender][_spender] = _value; | |
| return true; | |
| } | |
| /* Approve 받은 Contract 에게 알림 */ | |
| function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success_) { | |
| tokenReceipient spender = tokenReceipient(_spender); | |
| if (approve(_spender, _value)) { | |
| spender.receiveApproval(msg.sender, _value, this, _extraData); | |
| Approved(_spender, _value); | |
| return true; | |
| } | |
| } | |
| /* Contract 가 Token 을 가져가려 함 */ | |
| function transferFrom(address _from, address _to, uint256 _value) returns (bool success_) { | |
| if (balanceOf[_from] < _value) throw; | |
| if (balanceOf[_to] + _value < balanceOf[_to]) throw; | |
| if (_value > allowance[_from][msg.sender]) throw; | |
| balanceOf[_from] -= _value; | |
| balanceOf[_to] += _value; | |
| allowance[_from][msg.sender] -= _value; | |
| Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment