Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
b4f87bb8
Commit
b4f87bb8
authored
Sep 13, 2018
by
Leo Arias
Committed by
Nicolás Venturo
Sep 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename AutoIncrementing to Counter (#1307)
parent
225b4921
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
17 deletions
+18
-17
CounterImpl.sol
contracts/mocks/CounterImpl.sol
+5
-5
Counter.sol
contracts/utils/Counter.sol
+9
-9
Counter.test.js
test/Counter.test.js
+4
-3
No files found.
contracts/mocks/
AutoIncrementing
Impl.sol
→
contracts/mocks/
Counter
Impl.sol
View file @
b4f87bb8
pragma solidity ^0.4.24;
pragma solidity ^0.4.24;
import "../utils/
AutoIncrementing
.sol";
import "../utils/
Counter
.sol";
contract
AutoIncrementing
Impl {
contract
Counter
Impl {
using
AutoIncrementing for AutoIncrementing.Counter
;
using
Counter for Counter.Index
;
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 =>
AutoIncrementing.Counter
) private _counters;
mapping(string =>
Counter.Index
) private _counters;
function doThing(string key)
function doThing(string key)
public
public
returns (uint256)
returns (uint256)
{
{
theId = _counters[key].next
Id
();
theId = _counters[key].next();
return theId;
return theId;
}
}
}
}
contracts/utils/
AutoIncrementing
.sol
→
contracts/utils/
Counter
.sol
View file @
b4f87bb8
...
@@ -2,28 +2,28 @@ pragma solidity ^0.4.24;
...
@@ -2,28 +2,28 @@ pragma solidity ^0.4.24;
/**
/**
* @title
AutoIncrementing
* @title
Counter
* @author Matt Condon (@shrugs)
* @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.
* 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.
* @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
* so it's not something you have to worry about.)
* so it's not something you have to worry about.)
*/
*/
library
AutoIncrementing
{
library
Counter
{
struct
Counter
{
struct
Index
{
uint256
prev
Id; // default: 0
uint256
current
Id; // default: 0
}
}
function next
Id(Counter storage counter
)
function next
(Index storage index
)
internal
internal
returns (uint256)
returns (uint256)
{
{
counter.prevId = counter.prev
Id + 1;
index.currentId = index.current
Id + 1;
return
counter.prev
Id;
return
index.current
Id;
}
}
}
}
test/
AutoIncrementing
.test.js
→
test/
Counter
.test.js
View file @
b4f87bb8
const
AutoIncrementing
=
artifacts
.
require
(
'AutoIncrementingImpl'
);
const
Counter
=
artifacts
.
require
(
'CounterImpl'
);
require
(
'chai'
)
require
(
'chai'
)
.
use
(
require
(
'chai-bignumber'
)(
web3
.
BigNumber
))
.
use
(
require
(
'chai-bignumber'
)(
web3
.
BigNumber
))
...
@@ -8,9 +9,9 @@ const EXPECTED = [1, 2, 3, 4];
...
@@ -8,9 +9,9 @@ const EXPECTED = [1, 2, 3, 4];
const
KEY1
=
web3
.
sha3
(
'key1'
);
const
KEY1
=
web3
.
sha3
(
'key1'
);
const
KEY2
=
web3
.
sha3
(
'key2'
);
const
KEY2
=
web3
.
sha3
(
'key2'
);
contract
(
'
AutoIncrementing
'
,
function
([
_
,
owner
])
{
contract
(
'
Counter
'
,
function
([
_
,
owner
])
{
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
this
.
mock
=
await
AutoIncrementing
.
new
({
from
:
owner
});
this
.
mock
=
await
Counter
.
new
({
from
:
owner
});
});
});
context
(
'custom key'
,
async
function
()
{
context
(
'custom key'
,
async
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment