aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol')
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol79
1 files changed, 66 insertions, 13 deletions
diff --git a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
index d9950145d..5ef5ee7ce 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
@@ -21,15 +21,21 @@ pragma solidity 0.4.24;
import "./IERC20Token.sol";
-contract ERC20Token is IERC20Token {
+contract ERC20Token is
+ IERC20Token
+{
mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed;
- uint256 public totalSupply;
+ uint256 internal _totalSupply;
+ /// @dev send `value` token to `to` from `msg.sender`
+ /// @param _to The address of the recipient
+ /// @param _value The amount of token to be transferred
+ /// @return True if transfer was successful
function transfer(address _to, uint256 _value)
- public
+ external
returns (bool)
{
require(
@@ -38,16 +44,32 @@ contract ERC20Token is IERC20Token {
);
require(
balances[_to] + _value >= balances[_to],
- "OVERFLOW"
+ "UINT256_OVERFLOW"
);
+
balances[msg.sender] -= _value;
balances[_to] += _value;
- emit Transfer(msg.sender, _to, _value);
+
+ emit Transfer(
+ msg.sender,
+ _to,
+ _value
+ );
+
return true;
}
- function transferFrom(address _from, address _to, uint256 _value)
- public
+ /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
+ /// @param _from The address of the sender
+ /// @param _to The address of the recipient
+ /// @param _value The amount of token to be transferred
+ /// @return True if transfer was successful
+ function transferFrom(
+ address _from,
+ address _to,
+ uint256 _value
+ )
+ external
returns (bool)
{
require(
@@ -60,34 +82,65 @@ contract ERC20Token is IERC20Token {
);
require(
balances[_to] + _value >= balances[_to],
- "OVERFLOW"
+ "UINT256_OVERFLOW"
);
+
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
- emit Transfer(_from, _to, _value);
+
+ emit Transfer(
+ _from,
+ _to,
+ _value
+ );
+
return true;
}
+ /// @dev `msg.sender` approves `_spender` to spend `_value` tokens
+ /// @param _spender The address of the account able to transfer the tokens
+ /// @param _value The amount of wei to be approved for transfer
+ /// @return Always true if the call has enough gas to complete execution
function approve(address _spender, uint256 _value)
- public
+ external
returns (bool)
{
allowed[msg.sender][_spender] = _value;
- emit Approval(msg.sender, _spender, _value);
+ emit Approval(
+ msg.sender,
+ _spender,
+ _value
+ );
return true;
}
+ /// @dev Query total supply of token
+ /// @return Total supply of token
+ function totalSupply()
+ external
+ view
+ returns (uint256)
+ {
+ return _totalSupply;
+ }
+
+ /// @dev Query the balance of owner
+ /// @param _owner The address from which the balance will be retrieved
+ /// @return Balance of owner
function balanceOf(address _owner)
- public
+ external
view
returns (uint256)
{
return balances[_owner];
}
+ /// @param _owner The address of the account owning tokens
+ /// @param _spender The address of the account able to transfer the tokens
+ /// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender)
- public
+ external
view
returns (uint256)
{