Changes to Counter (#1332)

* rename Index.currentId to current

* use += operator for clarity

* rename Counter.Index to Counter.Counter

* move Counter to drafts

(cherry picked from commit 3e55408cb5)
This commit is contained in:
Francisco Giordano
2018-09-18 17:42:31 -03:00
parent 658af64edd
commit 6c36bc71a7
3 changed files with 10 additions and 10 deletions

View File

@ -0,0 +1,29 @@
pragma solidity ^0.4.24;
/**
* @title Counter
* @author Matt Condon (@shrugs)
* @dev Provides an incrementing uint256 id acquired by the `Counter#next` getter.
* Use this for issuing ERC721 ids or keeping track of request ids, anything you want, really.
*
* Include with `using Counter for Counter.Counter;`
* @notice Does not allow an Id of 0, which is popularly used to signify a null state in solidity.
* Does not protect from overflows, but if you have 2^256 ids, you have other problems.
* (But actually, it's generally impossible to increment a counter this many times, energy wise
* so it's not something you have to worry about.)
*/
library Counter {
struct Counter {
uint256 current; // default: 0
}
function next(Counter storage index)
internal
returns (uint256)
{
index.current += 1;
return index.current;
}
}