Skip to content

Commit 993e704

Browse files
authored
Merge pull request #21 from SpringRole/audit-fixes
remove fallback function & updated mint and max supply function.
2 parents 7261ff4 + 196cfaf commit 993e704

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

contracts/SRTToken.sol

Lines changed: 56 additions & 14 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,19 +62,57 @@ 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+
require(allowed[msg.sender][_spender] == 0);
5981
allowed[msg.sender][_spender] = _value;
6082
Approval(msg.sender, _spender, _value);
6183
return true;
6284
}
6385

86+
/**
87+
* @dev Function to check the amount of tokens that an owner allowed to a spender.
88+
* @param _owner address The address which owns the funds.
89+
* @param _spender address The address which will spend the funds.
90+
* @return A uint256 specifing the amount of tokens still available for the spender.
91+
*/
6492
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
6593
return allowed[_owner][_spender];
6694
}
95+
96+
/**
97+
* To increment allowed value is better to use this function.
98+
* From MonolithDAO Token.sol
99+
*/
100+
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
101+
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
102+
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
103+
return true;
104+
}
105+
106+
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
107+
uint oldValue = allowed[msg.sender][_spender];
108+
if (_subtractedValue > oldValue) {
109+
allowed[msg.sender][_spender] = 0;
110+
} else {
111+
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
112+
}
113+
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
114+
return true;
115+
}
67116
}
68117

69118
contract Ownable {
@@ -131,22 +180,22 @@ library SafeMath {
131180

132181
/* Contract class for adding removing whitelisted contracts */
133182
contract WhiteListedContracts is Ownable {
134-
mapping (address => uint ) white_listed_contracts;
183+
mapping (address => bool ) white_listed_contracts;
135184

136185
//modifer to check if the contract given is white listed or not
137186
modifier whitelistedContractsOnly() {
138-
require(white_listed_contracts[msg.sender] == 1);
187+
require(white_listed_contracts[msg.sender]);
139188
_;
140189
}
141190

142191
//add a contract to whitelist
143192
function addWhiteListedContracts (address _address) onlyOwner public {
144-
white_listed_contracts[_address] = 1;
193+
white_listed_contracts[_address] = true;
145194
}
146195

147196
//remove contract from whitelist
148197
function removeWhiteListedContracts (address _address) onlyOwner public {
149-
white_listed_contracts[_address] = 0;
198+
white_listed_contracts[_address] = false;
150199
}
151200
}
152201

@@ -160,18 +209,11 @@ contract SRTToken is Ownable,StandardToken,WhiteListedContracts {
160209
uint256 public totalSupply;
161210
uint256 public maxSupply;
162211

163-
/* Contructor function to set initial balance and assign to owner*/
212+
/* Contructor function to set maxSupply*/
164213
function SRTToken(uint256 _maxSupply){
165-
maxSupply = _maxSupply * 10**decimals;
214+
maxSupply = _maxSupply.mul(10**decimals);
166215
}
167216

168-
/*
169-
transfer eth recived to owner account if any
170-
*/
171-
function() payable {
172-
owner.transfer(msg.value);
173-
}
174-
175217
/*
176218
do transfer function will allow transfer from a _to to _from provided if the call
177219
comes from whitelisted contracts only
@@ -190,7 +232,7 @@ contract SRTToken is Ownable,StandardToken,WhiteListedContracts {
190232
* @return A boolean that indicates if the operation was successful.
191233
*/
192234
function mint(uint256 _amount) onlyOwner public returns (bool) {
193-
require(maxSupply>(totalSupply.add(_amount)));
235+
require (maxSupply >= (totalSupply.add(_amount)));
194236
totalSupply = totalSupply.add(_amount);
195237
balances[msg.sender] = balances[msg.sender].add(_amount);
196238
Transfer(address(0), msg.sender, _amount);

0 commit comments

Comments
 (0)