Update ERC20Token
This commit is contained in:
@@ -41,7 +41,7 @@ contract DummyERC20Token is
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
decimals = _decimals;
|
||||
totalSupply = _totalSupply;
|
||||
_totalSupply = _totalSupply;
|
||||
balances[msg.sender] = _totalSupply;
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ contract DummyERC20Token is
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
uint256 currBalance = balanceOf(_target);
|
||||
uint256 currBalance = balances[_target];
|
||||
if (_value < currBalance) {
|
||||
totalSupply = safeSub(totalSupply, safeSub(currBalance, _value));
|
||||
_totalSupply = safeSub(_totalSupply, safeSub(currBalance, _value));
|
||||
} else {
|
||||
totalSupply = safeAdd(totalSupply, safeSub(_value, currBalance));
|
||||
_totalSupply = safeAdd(_totalSupply, safeSub(_value, currBalance));
|
||||
}
|
||||
balances[_target] = _value;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ contract DummyERC721Receiver is
|
||||
IERC721Receiver
|
||||
{
|
||||
|
||||
// Function selector for ERC721Receiver.onERC721Received
|
||||
// 0x150b7a02
|
||||
bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
|
||||
|
||||
event TokenReceived(
|
||||
address from,
|
||||
uint256 tokenId,
|
||||
|
||||
@@ -38,6 +38,6 @@ contract Mintable is
|
||||
"Minting more than 100000000000000000000 is not allowed."
|
||||
);
|
||||
balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
|
||||
totalSupply = safeAdd(totalSupply, _value);
|
||||
_totalSupply = safeAdd(_totalSupply, _value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 +44,7 @@ contract ERC20Token is IERC20Token {
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"OVERFLOW"
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
balances[msg.sender] -= _value;
|
||||
balances[_to] += _value;
|
||||
@@ -46,8 +52,17 @@ contract ERC20Token is IERC20Token {
|
||||
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,7 +75,7 @@ contract ERC20Token is IERC20Token {
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"OVERFLOW"
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
@@ -69,25 +84,49 @@ contract ERC20Token is IERC20Token {
|
||||
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 enough 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)
|
||||
{
|
||||
|
||||
@@ -21,44 +21,6 @@ pragma solidity 0.4.24;
|
||||
|
||||
contract IERC20Token {
|
||||
|
||||
/// @notice 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 Whether the transfer was successful or not
|
||||
function transfer(address _to, uint256 _value)
|
||||
public
|
||||
returns (bool);
|
||||
|
||||
/// @notice 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 Whether the transfer was successful or not
|
||||
function transferFrom(address _from, address _to, uint256 _value)
|
||||
public
|
||||
returns (bool);
|
||||
|
||||
/// @notice `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 Whether the approval was successful or not
|
||||
function approve(address _spender, uint256 _value)
|
||||
public
|
||||
returns (bool);
|
||||
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return The balance
|
||||
function balanceOf(address _owner)
|
||||
public view
|
||||
returns (uint256);
|
||||
|
||||
/// @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 view
|
||||
returns (uint256);
|
||||
|
||||
// solhint-disable-next-line no-simple-event-func-name
|
||||
event Transfer(
|
||||
address indexed _from,
|
||||
@@ -71,4 +33,55 @@ contract IERC20Token {
|
||||
address indexed _spender,
|
||||
uint256 _value
|
||||
);
|
||||
|
||||
/// @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)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @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);
|
||||
|
||||
/// @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 enough call has enough gas to complete execution
|
||||
function approve(address _spender, uint256 _value)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev Query total supply of token
|
||||
/// @return Total supply of token
|
||||
function totalSupply()
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return Balance of owner
|
||||
function balanceOf(address _owner)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @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)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ pragma solidity 0.4.24;
|
||||
import "../ERC20Token/ERC20Token.sol";
|
||||
|
||||
|
||||
contract UnlimitedAllowanceToken is ERC20Token {
|
||||
contract UnlimitedAllowanceToken is
|
||||
ERC20Token
|
||||
{
|
||||
|
||||
uint256 constant internal MAX_UINT = 2**256 - 1;
|
||||
|
||||
@@ -30,8 +32,12 @@ contract UnlimitedAllowanceToken is ERC20Token {
|
||||
/// @param _to Address to transfer to.
|
||||
/// @param _value Amount to transfer.
|
||||
/// @return Success of transfer.
|
||||
function transferFrom(address _from, address _to, uint256 _value)
|
||||
public
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
uint256 allowance = allowed[_from][msg.sender];
|
||||
@@ -45,14 +51,18 @@ contract UnlimitedAllowanceToken is ERC20Token {
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"OVERFLOW"
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
if (allowance < MAX_UINT) {
|
||||
allowed[_from][msg.sender] -= _value;
|
||||
}
|
||||
emit Transfer(_from, _to, _value);
|
||||
emit Transfer(
|
||||
_from,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user