Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.0;
- /**
- public - 안 밖에서 자유롭게 접근가능
- internal - 계약서 안에서 실행 가능한 함수를 통해서만 접근 가능
- external - 외부 계약서의 트랜잭션을 통해서만 접근 가능
- private - 계약서 내부일지라도 다른데서 상속받은 함수들이 아닌 순수 계약서만의 함수에서만 접근 가능
- */
- contract tokenRecipient {
- function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external;
- }
- contract RankingballToken {
- // Token 의 Public 변수 들
- string public standard = "Rankingball 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 RankingballToken (uint256 initialSupply, string tokenName, uint8 decimalUnits, string tokenSymbol) public {
- balanceOf[msg.sender] = initialSupply;
- totalSupply = initialSupply;
- name = tokenName;
- symbol = tokenSymbol;
- decimals = decimalUnits;
- }
- /**
- * Token 이체, only can be called by this contract
- */
- function _transfer(address _from, address _to, uint256 _value) internal {
- //if (balanceOf[msg.sender] < _value) throw; // throw deprecated
- //if (balanceOf[_to] + _value < balanceOf[_to]) throw; // throw deprecated
- // prevent transfer to 0x0 address. Use burn() instead
- require(_to != 0x0);
- // check if the sender has enough
- require(balanceOf[_from] >= _value);
- // check for overflows
- require(balanceOf[_to] + _value > balanceOf[_to]);
- balanceOf[_from] -= _value;
- balanceOf[_to] += _value;
- emit Transfer(_from, _to, _value);
- }
- /**
- * Transfer tokens
- *
- * Send `_value` tokens to `_to` from your account
- *
- * @param _to The address of the recipient
- * @param _value the amount to send
- */
- function transfer(address _to, uint256 _value) public {
- _transfer(msg.sender, _to, _value);
- }
- /* 특정 Contract 가 내 대신 Token 을 쓸 수 있도록 함 */
- function approve(address _spender, uint256 _value) public returns (bool success_) {
- allowance[msg.sender][_spender] = _value;
- return true;
- }
- /* Approve 받은 Contract 에게 알림 */
- function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success_) {
- tokenRecipient spender = tokenRecipient(_spender);
- if (approve(_spender, _value)) {
- spender.receiveApproval(msg.sender, _value, this, _extraData);
- emit Approved(_spender, _value);
- return true;
- }
- }
- /**
- * Transfer tokens from other address
- *
- * Send `_value` tokens to `_to` in behalf of `_from`
- *
- * @param _from The address of the sender
- * @param _to The address of the recipient
- * @param _value the amount to send
- *
- * Contract 가 Token 을 가져가려 함
- */
- function transferFrom(address _from, address _to, uint256 _value) public returns (bool success_) {
- //if (balanceOf[_from] < _value) throw;
- //if (balanceOf[_to] + _value < balanceOf[_to]) throw;
- //if (_value > allowance[_from][msg.sender]) throw;
- /*
- // check if the sender has enough
- require(balanceOf[_from] >= _value);
- // check for overflows
- require(balanceOf[_to] + _value > balanceOf[_to]);
- // check allowance
- require(_value <= allowance[_from][msg.sender]);
- balanceOf[_from] -= _value;
- balanceOf[_to] += _value;
- allowance[_from][msg.sender] -= _value;
- emit Transfer(_from, _to, _value);*/
- // check allowance
- require(_value <= allowance[_from][msg.sender]);
- allowance[_from][msg.sender] -= _value;
- _transfer(_from, _to, _value);
- return true;
- }
- }
Add Comment
Please, Sign In to add comment