|
@@ -1,7 +1,7 @@
|
|
|
pragma solidity ^0.4.24;
|
|
|
|
|
|
-import "./BasicToken.sol";
|
|
|
import "./ERC20.sol";
|
|
|
+import "../../math/SafeMath.sol";
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -11,33 +11,60 @@ import "./ERC20.sol";
|
|
|
* https://github.com/ethereum/EIPs/issues/20
|
|
|
* Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
|
|
|
*/
|
|
|
-contract StandardToken is ERC20, BasicToken {
|
|
|
+contract StandardToken is ERC20 {
|
|
|
+ using SafeMath for uint256;
|
|
|
+
|
|
|
+ mapping(address => uint256) balances;
|
|
|
|
|
|
mapping (address => mapping (address => uint256)) internal allowed;
|
|
|
|
|
|
+ uint256 totalSupply_;
|
|
|
|
|
|
/**
|
|
|
- * @dev Transfer tokens from one address to another
|
|
|
- * @param _from address The address which you want to send tokens from
|
|
|
- * @param _to address The address which you want to transfer to
|
|
|
- * @param _value uint256 the amount of tokens to be transferred
|
|
|
+ * @dev Total number of tokens in existence
|
|
|
+ */
|
|
|
+ function totalSupply() public view returns (uint256) {
|
|
|
+ return totalSupply_;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dev Gets the balance of the specified address.
|
|
|
+ * @param _owner The address to query the the balance of.
|
|
|
+ * @return An uint256 representing the amount owned by the passed address.
|
|
|
+ */
|
|
|
+ function balanceOf(address _owner) public view returns (uint256) {
|
|
|
+ return balances[_owner];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
|
|
|
+ * @param _owner address The address which owns the funds.
|
|
|
+ * @param _spender address The address which will spend the funds.
|
|
|
+ * @return A uint256 specifying the amount of tokens still available for the spender.
|
|
|
*/
|
|
|
- function transferFrom(
|
|
|
- address _from,
|
|
|
- address _to,
|
|
|
- uint256 _value
|
|
|
- )
|
|
|
+ function allowance(
|
|
|
+ address _owner,
|
|
|
+ address _spender
|
|
|
+ )
|
|
|
public
|
|
|
- returns (bool)
|
|
|
+ view
|
|
|
+ returns (uint256)
|
|
|
{
|
|
|
- require(_value <= balances[_from]);
|
|
|
- require(_value <= allowed[_from][msg.sender]);
|
|
|
+ return allowed[_owner][_spender];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dev Transfer token for a specified address
|
|
|
+ * @param _to The address to transfer to.
|
|
|
+ * @param _value The amount to be transferred.
|
|
|
+ */
|
|
|
+ function transfer(address _to, uint256 _value) public returns (bool) {
|
|
|
+ require(_value <= balances[msg.sender]);
|
|
|
require(_to != address(0));
|
|
|
|
|
|
- balances[_from] = balances[_from].sub(_value);
|
|
|
+ balances[msg.sender] = balances[msg.sender].sub(_value);
|
|
|
balances[_to] = balances[_to].add(_value);
|
|
|
- allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
|
|
|
- emit Transfer(_from, _to, _value);
|
|
|
+ emit Transfer(msg.sender, _to, _value);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -57,20 +84,28 @@ contract StandardToken is ERC20, BasicToken {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @dev Function to check the amount of tokens that an owner allowed to a spender.
|
|
|
- * @param _owner address The address which owns the funds.
|
|
|
- * @param _spender address The address which will spend the funds.
|
|
|
- * @return A uint256 specifying the amount of tokens still available for the spender.
|
|
|
+ * @dev Transfer tokens from one address to another
|
|
|
+ * @param _from address The address which you want to send tokens from
|
|
|
+ * @param _to address The address which you want to transfer to
|
|
|
+ * @param _value uint256 the amount of tokens to be transferred
|
|
|
*/
|
|
|
- function allowance(
|
|
|
- address _owner,
|
|
|
- address _spender
|
|
|
- )
|
|
|
+ function transferFrom(
|
|
|
+ address _from,
|
|
|
+ address _to,
|
|
|
+ uint256 _value
|
|
|
+ )
|
|
|
public
|
|
|
- view
|
|
|
- returns (uint256)
|
|
|
+ returns (bool)
|
|
|
{
|
|
|
- return allowed[_owner][_spender];
|
|
|
+ require(_value <= balances[_from]);
|
|
|
+ require(_value <= allowed[_from][msg.sender]);
|
|
|
+ require(_to != address(0));
|
|
|
+
|
|
|
+ balances[_from] = balances[_from].sub(_value);
|
|
|
+ balances[_to] = balances[_to].add(_value);
|
|
|
+ allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
|
|
|
+ emit Transfer(_from, _to, _value);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
/**
|