Remove utils/Counters.sol (#4289)
Co-authored-by: Francisco Giordano <fg@frang.io>
This commit is contained in:
@ -1,43 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
|
||||
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
/**
|
||||
* @title Counters
|
||||
* @author Matt Condon (@shrugs)
|
||||
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
|
||||
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
|
||||
*
|
||||
* Include with `using Counters for Counters.Counter;`
|
||||
*/
|
||||
library Counters {
|
||||
struct Counter {
|
||||
// This variable should never be directly accessed by users of the library: interactions must be restricted to
|
||||
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
|
||||
// this feature: see https://github.com/ethereum/solidity/issues/4637
|
||||
uint256 _value; // default: 0
|
||||
}
|
||||
|
||||
function current(Counter storage counter) internal view returns (uint256) {
|
||||
return counter._value;
|
||||
}
|
||||
|
||||
function increment(Counter storage counter) internal {
|
||||
unchecked {
|
||||
counter._value += 1;
|
||||
}
|
||||
}
|
||||
|
||||
function decrement(Counter storage counter) internal {
|
||||
uint256 value = counter._value;
|
||||
require(value > 0, "Counter: decrement overflow");
|
||||
unchecked {
|
||||
counter._value = value - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function reset(Counter storage counter) internal {
|
||||
counter._value = 0;
|
||||
}
|
||||
}
|
||||
@ -1,21 +1,17 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import "./Counters.sol";
|
||||
|
||||
/**
|
||||
* @dev Provides tracking nonces for addresses. Nonces will only increment.
|
||||
*/
|
||||
abstract contract Nonces {
|
||||
using Counters for Counters.Counter;
|
||||
|
||||
mapping(address => Counters.Counter) private _nonces;
|
||||
mapping(address => uint256) private _nonces;
|
||||
|
||||
/**
|
||||
* @dev Returns an address nonce.
|
||||
*/
|
||||
function nonces(address owner) public view virtual returns (uint256) {
|
||||
return _nonces[owner].current();
|
||||
return _nonces[owner];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,9 +19,12 @@ abstract contract Nonces {
|
||||
*
|
||||
* Returns the current value and increments nonce.
|
||||
*/
|
||||
function _useNonce(address owner) internal virtual returns (uint256 current) {
|
||||
Counters.Counter storage nonce = _nonces[owner];
|
||||
current = nonce.current();
|
||||
nonce.increment();
|
||||
function _useNonce(address owner) internal virtual returns (uint256) {
|
||||
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
|
||||
// decremented or reset. This guarantees that the nonce never overflows.
|
||||
unchecked {
|
||||
// It is important to do x++ and not ++x here.
|
||||
return _nonces[owner]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ The {Address}, {Arrays}, {Base64} and {Strings} libraries provide more operation
|
||||
|
||||
For new data types:
|
||||
|
||||
* {Counters}: a simple way to get a counter that can only be incremented, decremented or reset. Very useful for ID generation, counting contract activity, among others.
|
||||
* {EnumerableMap}: like Solidity's https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] type, but with key-value _enumeration_: this will let you know how many entries a mapping has, and iterate over them (which is not possible with `mapping`).
|
||||
* {EnumerableSet}: like {EnumerableMap}, but for https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets]. Can be used to store privileged accounts, issued IDs, etc.
|
||||
|
||||
@ -75,8 +74,6 @@ Ethereum contracts have no native concept of an interface, so applications must
|
||||
|
||||
{{Base64}}
|
||||
|
||||
{{Counters}}
|
||||
|
||||
{{Strings}}
|
||||
|
||||
{{ShortStrings}}
|
||||
|
||||
Reference in New Issue
Block a user