Unverified Commit 3e55408c by Francisco Giordano Committed by GitHub

Changes to Counter (#1332)

* rename Index.currentId to current

* use += operator for clarity

* rename Counter.Index to Counter.Counter

* move Counter to drafts
parent 4b21fcf5
...@@ -4,10 +4,10 @@ pragma solidity ^0.4.24; ...@@ -4,10 +4,10 @@ pragma solidity ^0.4.24;
/** /**
* @title Counter * @title Counter
* @author Matt Condon (@shrugs) * @author Matt Condon (@shrugs)
* @dev Provides an incrementing uint256 id acquired by the `Index#next` getter. * @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. * Use this for issuing ERC721 ids or keeping track of request ids, anything you want, really.
* *
* Include with `using Counter for Counter.Index;` * 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. * @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. * 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 * (But actually, it's generally impossible to increment a counter this many times, energy wise
...@@ -15,15 +15,15 @@ pragma solidity ^0.4.24; ...@@ -15,15 +15,15 @@ pragma solidity ^0.4.24;
*/ */
library Counter { library Counter {
struct Index { struct Counter {
uint256 currentId; // default: 0 uint256 current; // default: 0
} }
function next(Index storage index) function next(Counter storage index)
internal internal
returns (uint256) returns (uint256)
{ {
index.currentId = index.currentId + 1; index.current += 1;
return index.currentId; return index.current;
} }
} }
pragma solidity ^0.4.24; pragma solidity ^0.4.24;
import "../utils/Counter.sol"; import "../drafts/Counter.sol";
contract CounterImpl { contract CounterImpl {
using Counter for Counter.Index; using Counter for Counter.Counter;
uint256 public theId; uint256 public theId;
// use whatever key you want to track your counters // use whatever key you want to track your counters
mapping(string => Counter.Index) private _counters; mapping(string => Counter.Counter) private _counters;
function doThing(string key) function doThing(string key)
public public
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment