Skip to content

Commit 0effca9

Browse files
author
ken woodruff
committed
Fixed bug with _getNextToken() where burning a token will result in
_getNextToken() potentially returning a tokenId which has already been allocated, which would result in a revert when the next _mint() is called. Added a private _currentTokenId which is initalized to 0 and MUST be manually incremented by calling _incrementTokenId(), after each _mint() is called.
1 parent ba16eb8 commit 0effca9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

‎contracts/TradeableERC721Token.sol‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ contract TradeableERC721Token is ERC721Full, Ownable {
1818
using Strings for string;
1919

2020
address proxyRegistryAddress;
21+
uint256 private _currentTokenId = 0;
2122

2223
constructor(string memory _name, string memory _symbol, address _proxyRegistryAddress) ERC721Full(_name, _symbol) public {
2324
proxyRegistryAddress = _proxyRegistryAddress;
@@ -30,14 +31,22 @@ contract TradeableERC721Token is ERC721Full, Ownable {
3031
function mintTo(address _to) public onlyOwner {
3132
uint256 newTokenId = _getNextTokenId();
3233
_mint(_to, newTokenId);
34+
_incrementTokenId();
3335
}
3436

3537
/**
36-
* @dev calculates the next token ID based on totalSupply
38+
* @dev calculates the next token ID based on value of _currentTokenId
3739
* @return uint256 for the next token ID
3840
*/
3941
function _getNextTokenId() private view returns (uint256) {
40-
return totalSupply().add(1);
42+
return _currentTokenId.add(1);
43+
}
44+
45+
/**
46+
* @dev increments the value of _currentTokenId
47+
*/
48+
function _incrementTokenId() private {
49+
_currentTokenId++;
4150
}
4251

4352
function baseTokenURI() public view returns (string memory) {
@@ -70,4 +79,4 @@ contract TradeableERC721Token is ERC721Full, Ownable {
7079

7180
return super.isApprovedForAll(owner, operator);
7281
}
73-
}
82+
}

0 commit comments

Comments
 (0)