Skip to content

Commit 8d4f3e8

Browse files
committed
added comment and approval fixes
1 parent 0b966a6 commit 8d4f3e8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

contracts/SRTToken.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ contract StandardToken is ERC20 {
3434
mapping (address => uint256) public balances;
3535
mapping (address => mapping (address => uint256)) public allowed;
3636

37+
/**
38+
* @dev transfer token for a specified address
39+
* @param _to The address to transfer to.
40+
* @param _value The amount to be transferred.
41+
*/
3742
function transfer(address _to, uint256 _value) returns (bool success) {
3843
require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]);
3944
balances[msg.sender] = balances[msg.sender].sub(_value);
@@ -42,6 +47,12 @@ contract StandardToken is ERC20 {
4247
return true;
4348
}
4449

50+
/**
51+
* @dev Transfer tokens from one address to another
52+
* @param _from address The address which you want to send tokens from
53+
* @param _to address The address which you want to transfer to
54+
* @param _value uint256 the amout of tokens to be transfered
55+
*/
4556
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
4657
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]);
4758
balances[_to] = balances[_to].add(_value);
@@ -51,16 +62,37 @@ contract StandardToken is ERC20 {
5162
return true;
5263
}
5364

65+
/**
66+
* @dev Gets the balance of the specified address.
67+
* @param _owner The address to query the the balance of.
68+
* @return An uint256 representing the amount owned by the passed address.
69+
*/
5470
function balanceOf(address _owner) constant returns (uint256 balance) {
5571
return balances[_owner];
5672
}
5773

74+
/**
75+
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
76+
* @param _spender The address which will spend the funds.
77+
* @param _value The amount of tokens to be spent.
78+
*/
5879
function approve(address _spender, uint256 _value) returns (bool success) {
80+
// To change the approve amount you first have to reduce the addresses`
81+
// allowance to zero by calling `approve(_spender, 0)` if it is not
82+
// already 0 to mitigate the race condition described here:
83+
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
84+
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
5985
allowed[msg.sender][_spender] = _value;
6086
Approval(msg.sender, _spender, _value);
6187
return true;
6288
}
6389

90+
/**
91+
* @dev Function to check the amount of tokens that an owner allowed to a spender.
92+
* @param _owner address The address which owns the funds.
93+
* @param _spender address The address which will spend the funds.
94+
* @return A uint256 specifing the amount of tokens still available for the spender.
95+
*/
6496
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
6597
return allowed[_owner][_spender];
6698
}

0 commit comments

Comments
 (0)