github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/xc/eth-v1.0.3/INK.sol (about)

     1  // Abstract contract for the full ERC 20 Token standard
     2  // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
     3  pragma solidity ^0.4.21;
     4  
     5  
     6  contract EIP20Interface {
     7      /* This is a slight change to the ERC20 base standard.
     8      function totalSupply() constant returns (uint256 supply);
     9      is replaced with:
    10      uint256 public totalSupply;
    11      This automatically creates a getter function for the totalSupply.
    12      This is moved to the base contract since public getter functions are not
    13      currently recognised as an implementation of the matching abstract
    14      function by the compiler.
    15      */
    16      /// total amount of tokens
    17      uint256 public totalSupply;
    18  
    19      /// @param _owner The address from which the balance will be retrieved
    20      /// @return The balance
    21      function balanceOf(address _owner) public view returns (uint256 balance);
    22  
    23      /// @notice send `_value` token to `_to` from `msg.sender`
    24      /// @param _to The address of the recipient
    25      /// @param _value The amount of token to be transferred
    26      /// @return Whether the transfer was successful or not
    27      function transfer(address _to, uint256 _value) public returns (bool success);
    28  
    29      /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    30      /// @param _from The address of the sender
    31      /// @param _to The address of the recipient
    32      /// @param _value The amount of token to be transferred
    33      /// @return Whether the transfer was successful or not
    34      function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
    35  
    36      /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
    37      /// @param _spender The address of the account able to transfer the tokens
    38      /// @param _value The amount of tokens to be approved for transfer
    39      /// @return Whether the approval was successful or not
    40      function approve(address _spender, uint256 _value) public returns (bool success);
    41  
    42      /// @param _owner The address of the account owning tokens
    43      /// @param _spender The address of the account able to transfer the tokens
    44      /// @return Amount of remaining tokens allowed to spent
    45      function allowance(address _owner, address _spender) public view returns (uint256 remaining);
    46  
    47      // solhint-disable-next-line no-simple-event-func-name
    48      event Transfer(address indexed _from, address indexed _to, uint256 _value);
    49      event Approval(address indexed _owner, address indexed _spender, uint256 _value);
    50  }
    51  
    52  contract INK is EIP20Interface {
    53  
    54      uint256 constant private MAX_UINT256 = 2**256 - 1;
    55      mapping (address => uint256) private balances;
    56      mapping (address => mapping (address => uint256)) private allowed;
    57      /*
    58      NOTE:
    59      The following variables are OPTIONAL vanities. One does not have to include them.
    60      They allow one to customise the token contract & in no way influences the core functionality.
    61      Some wallets/interfaces might not even bother to look at this information.
    62      */
    63      string public name;                   //fancy name: eg Simon Bucks
    64      uint8 public decimals;                //How many decimals to show.
    65      string public symbol;                 //An identifier: eg SBX
    66  
    67      function INK() public {
    68          totalSupply = 10 * (10**8) * (10**9);                // Update total supply
    69          balances[msg.sender] = totalSupply;                  // Give the creator all initial tokens
    70          name = 'INK token';                                  // Set the name for display purposes
    71          decimals = 9;                                        // Amount of decimals for display purposes
    72          symbol = 'INK';                                      // Set the symbol for display purposes
    73      }
    74  
    75      function transfer(address _to, uint256 _value) public returns (bool success) {
    76          require(balances[msg.sender] >= _value);
    77          balances[msg.sender] -= _value;
    78          balances[_to] += _value;
    79          emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
    80          return true;
    81      }
    82  
    83      function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
    84          uint256 allowance = allowed[_from][msg.sender];
    85          require(balances[_from] >= _value && allowance >= _value);
    86          balances[_to] += _value;
    87          balances[_from] -= _value;
    88          if (allowance < MAX_UINT256) {
    89              allowed[_from][msg.sender] -= _value;
    90          }
    91          emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
    92          return true;
    93      }
    94  
    95      function balanceOf(address _owner) public view returns (uint256 balance) {
    96          return balances[_owner];
    97      }
    98  
    99      function approve(address _spender, uint256 _value) public returns (bool success) {
   100          allowed[msg.sender][_spender] = _value;
   101          emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
   102          return true;
   103      }
   104  
   105      function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
   106          return allowed[_owner][_spender];
   107      }
   108  }