Rename AutoIncrementing to Counter (#1307)

This commit is contained in:
Leo Arias
2018-09-13 02:51:22 -06:00
committed by Nicolás Venturo
parent 225b492109
commit b4f87bb8fc
4 changed files with 34 additions and 33 deletions

View File

@ -2,28 +2,28 @@ pragma solidity ^0.4.24;
/**
* @title AutoIncrementing
* @title Counter
* @author Matt Condon (@shrugs)
* @dev Provides an auto-incrementing uint256 id acquired by the `Counter#nextId` getter.
* @dev Provides an incrementing uint256 id acquired by the `Index#next` getter.
* Use this for issuing ERC721 ids or keeping track of request ids, anything you want, really.
*
* Include with `using AutoIncrementing for AutoIncrementing.Counter;`
* Include with `using Counter for Counter.Index;`
* @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 AutoIncrementing {
library Counter {
struct Counter {
uint256 prevId; // default: 0
struct Index {
uint256 currentId; // default: 0
}
function nextId(Counter storage counter)
function next(Index storage index)
internal
returns (uint256)
{
counter.prevId = counter.prevId + 1;
return counter.prevId;
index.currentId = index.currentId + 1;
return index.currentId;
}
}