-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follows up #62 #### PR Checklist - [ ] Tests - [x] Documentation --------- Co-authored-by: Gustavo Gonzalez <gustavo.gonzalez@openzeppelin.com> (cherry picked from commit c40dc8e)
- Loading branch information
1 parent
762a0e5
commit 89ee202
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
* xref:access-control.adoc[Access Control] | ||
* xref:crypto.adoc[Cryptography] | ||
* xref:utilities.adoc[Utilities] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
= Utilities | ||
|
||
The OpenZeppelin Stylus Contracts provides a ton of useful utilities that you can use in your project. | ||
For a complete list, check out the https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/index.html[API Reference]. | ||
Here are some of the more popular ones. | ||
|
||
[[introspection]] | ||
== Introspection | ||
|
||
It's frequently helpful to know whether a contract supports an interface you'd like to use. | ||
https://eips.ethereum.org/EIPS/eip-165[`ERC-165`] is a standard that helps do runtime interface detection. | ||
Contracts for Stylus provides helpers for implementing ERC-165 in your contracts: | ||
|
||
* https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/introspection/erc165/trait.IErc165.html[`IERC165`] — this is the ERC-165 trait that defines https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/introspection/erc165/trait.IErc165.html#tymethod.supports_interface[`supportsInterface`]. In order to implement ERC-165 interface detection, you should manually expose https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/introspection/erc165/trait.IErc165.html#tymethod.supports_interface[`supportsInterface`] function in your contract. | ||
Check failure on line 14 in docs/modules/ROOT/pages/utilities.adoc GitHub Actions / Linkspector[linkspector] docs/modules/ROOT/pages/utilities.adoc#L14
Raw output
Check failure on line 14 in docs/modules/ROOT/pages/utilities.adoc GitHub Actions / Linkspector[linkspector] docs/modules/ROOT/pages/utilities.adoc#L14
Raw output
Check failure on line 14 in docs/modules/ROOT/pages/utilities.adoc GitHub Actions / Linkspector[linkspector] docs/modules/ROOT/pages/utilities.adoc#L14
Raw output
|
||
|
||
[source,rust] | ||
---- | ||
sol_storage! { | ||
#[entrypoint] | ||
struct Erc721Example { | ||
#[borrow] | ||
Erc721 erc721; | ||
} | ||
} | ||
#[public] | ||
#[inherit(Erc721)] | ||
impl Erc721Example { | ||
pub fn supports_interface(interface_id: FixedBytes<4>) -> bool { | ||
Erc721::supports_interface(interface_id) | ||
} | ||
} | ||
---- | ||
|
||
[[structures]] | ||
== Structures | ||
|
||
Some use cases require more powerful data structures than arrays and mappings offered natively in alloy and the Stylus sdk. | ||
Contracts for Stylus provides these libraries for enhanced data structure management: | ||
|
||
- https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/structs/bitmap/index.html[`BitMaps`]: Store packed booleans in storage. | ||
- https://docs.rs/openzeppelin-stylus/0.1.0-rc/openzeppelin_stylus/utils/structs/checkpoints/index.html[`Checkpoints`]: Checkpoint values with built-in lookups. |