From 6c36bc71a7ab1fa1cb2c471b42a017dba9b961c6 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Tue, 18 Sep 2018 17:42:31 -0300 Subject: [PATCH] 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 3e55408cb5590dc5095ebd766756ca2da356e1d8) --- contracts/{utils => drafts}/Counter.sol | 14 +++++++------- contracts/mocks/CounterImpl.sol | 6 +++--- test/{ => drafts}/Counter.test.js | 0 3 files changed, 10 insertions(+), 10 deletions(-) rename contracts/{utils => drafts}/Counter.sol (66%) rename test/{ => drafts}/Counter.test.js (100%) diff --git a/contracts/utils/Counter.sol b/contracts/drafts/Counter.sol similarity index 66% rename from contracts/utils/Counter.sol rename to contracts/drafts/Counter.sol index 516b798f0..b47d9b824 100644 --- a/contracts/utils/Counter.sol +++ b/contracts/drafts/Counter.sol @@ -4,10 +4,10 @@ pragma solidity ^0.4.24; /** * @title Counter * @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. * - * 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. * 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 @@ -15,15 +15,15 @@ pragma solidity ^0.4.24; */ library Counter { - struct Index { - uint256 currentId; // default: 0 + struct Counter { + uint256 current; // default: 0 } - function next(Index storage index) + function next(Counter storage index) internal returns (uint256) { - index.currentId = index.currentId + 1; - return index.currentId; + index.current += 1; + return index.current; } } diff --git a/contracts/mocks/CounterImpl.sol b/contracts/mocks/CounterImpl.sol index 222c0526e..d42fcbda2 100644 --- a/contracts/mocks/CounterImpl.sol +++ b/contracts/mocks/CounterImpl.sol @@ -1,15 +1,15 @@ pragma solidity ^0.4.24; -import "../utils/Counter.sol"; +import "../drafts/Counter.sol"; contract CounterImpl { - using Counter for Counter.Index; + using Counter for Counter.Counter; uint256 public theId; // 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) public diff --git a/test/Counter.test.js b/test/drafts/Counter.test.js similarity index 100% rename from test/Counter.test.js rename to test/drafts/Counter.test.js