Skip to content

Commit

Permalink
Changes to Counter (#1332)
Browse files Browse the repository at this point in the history
* rename Index.currentId to current

* use += operator for clarity

* rename Counter.Index to Counter.Counter

* move Counter to drafts

(cherry picked from commit 3e55408)
  • Loading branch information
frangio committed Sep 18, 2018
1 parent 658af64 commit 6c36bc7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions contracts/utils/Counter.sol → contracts/drafts/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ 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
* so it's not something you have to worry about.)
*/
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;
}
}
6 changes: 3 additions & 3 deletions contracts/mocks/CounterImpl.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.

0 comments on commit 6c36bc7

Please sign in to comment.