Add a Counter.reset function (#2678)
This commit is contained in:
@ -20,4 +20,8 @@ contract CountersImpl {
|
||||
function decrement() public {
|
||||
_counter.decrement();
|
||||
}
|
||||
|
||||
function reset() public {
|
||||
_counter.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
|
||||
/**
|
||||
* @title Counters
|
||||
* @author Matt Condon (@shrugs)
|
||||
* @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
|
||||
* @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;`
|
||||
@ -35,4 +35,8 @@ library Counters {
|
||||
counter._value = value - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function reset(Counter storage counter) internal {
|
||||
counter._value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ The {Address}, {Arrays} and {Strings} libraries provide more operations related
|
||||
|
||||
For new data types:
|
||||
|
||||
* {Counters}: a simple way to get a counter that can only be incremented or decremented. Very useful for ID generation, counting contract activity, among others.
|
||||
* {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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user