Improve Hooks documentation (#2199)
* Improve Hooks docs * Improve Utils docs * Apply suggestions from code review Co-Authored-By: Francisco Giordano <frangio.1@gmail.com> * Add enumerable code samples * Remove import statement from example Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -1,5 +1,29 @@
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
/**
|
||||
* @dev Library for managing an enumerable variant of Solidity's
|
||||
* https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
|
||||
* type.
|
||||
*
|
||||
* Maps have the following properties:
|
||||
*
|
||||
* - Entries are added, removed, and checked for existence in constant time
|
||||
* (O(1)).
|
||||
* - Entries are enumerated in O(n). No guarantees are made on the ordering.
|
||||
*
|
||||
* ```
|
||||
* contract Example {
|
||||
* // Add the library methods
|
||||
* using EnumerableMap for EnumerableMap.UintToAddressMap;
|
||||
*
|
||||
* // Declare a set state variable
|
||||
* EnumerableMap.UintToAddressMap private myMap;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
|
||||
* supported.
|
||||
*/
|
||||
library EnumerableMap {
|
||||
// To implement this library for multiple types with as little code
|
||||
// repetition as possible, we write it in terms of a generic Map type with
|
||||
|
||||
@ -11,11 +11,18 @@ pragma solidity ^0.6.0;
|
||||
* (O(1)).
|
||||
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
|
||||
*
|
||||
* As of v2.5.0, only `address` sets are supported.
|
||||
* ```
|
||||
* contract Example {
|
||||
* // Add the library methods
|
||||
* using EnumerableSet for EnumerableSet.AddressSet;
|
||||
*
|
||||
* Include with `using EnumerableSet for EnumerableSet.AddressSet;`.
|
||||
* // Declare a set state variable
|
||||
* EnumerableSet.AddressSet private mySet;
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @author Alberto Cuesta Cañada
|
||||
* As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256`
|
||||
* (`UintSet`) are supported.
|
||||
*/
|
||||
library EnumerableSet {
|
||||
// To implement this library for multiple types with as little code
|
||||
|
||||
@ -1,25 +1,49 @@
|
||||
= Utilities
|
||||
|
||||
Miscellaneous contracts containing utility functions, often related to working with different data types.
|
||||
Miscellaneous contracts and libraries containing utility functions you can use to improve security, work with new data types, or safely use low-level primitives.
|
||||
|
||||
Security tools include:
|
||||
|
||||
* {Pausable}: provides a simple way to halt activity in your contracts (often in reponse to an external threat).
|
||||
* {ReentrancyGuard}: protects you from https://blog.openzeppelin.com/reentrancy-after-istanbul/[reentrant calls].
|
||||
|
||||
The {Address}, {Arrays} and {Strings} libraries provide more operations related to these native data types, while {SafeCast} adds ways to safely convert between the different signed and unsigned numeric types.
|
||||
|
||||
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.
|
||||
* {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.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
Because Solidity does not support generic types, {EnumerableMap} and {EnumerableSet} are specialized to a limited number of key-value types.
|
||||
|
||||
As of v3.0, {EnumerableMap} supports `uint256 -> address` (`UintToAddressMap`), and {EnumerableSet} supports `address` and `uint256` (`AddressSet` and `UintSet`).
|
||||
====
|
||||
|
||||
Finally, {Create2} contains all necessary utilities to safely use the https://blog.openzeppelin.com/getting-the-most-out-of-create2/[`CREATE2` EVM opcode], without having to deal with low-level assembly.
|
||||
|
||||
== Contracts
|
||||
|
||||
{{Address}}
|
||||
{{Pausable}}
|
||||
|
||||
{{SafeCast}}
|
||||
{{ReentrancyGuard}}
|
||||
|
||||
== Libraries
|
||||
|
||||
{{Address}}
|
||||
|
||||
{{Arrays}}
|
||||
|
||||
{{Counters}}
|
||||
|
||||
{{Strings}}
|
||||
|
||||
{{EnumerableSet}}
|
||||
{{Create2}}
|
||||
|
||||
{{EnumerableMap}}
|
||||
|
||||
{{Create2}}
|
||||
{{EnumerableSet}}
|
||||
|
||||
{{ReentrancyGuard}}
|
||||
{{SafeCast}}
|
||||
|
||||
{{Pausable}}
|
||||
{{Strings}}
|
||||
|
||||
Reference in New Issue
Block a user