Diamond Inspect Facet
Inspect diamond facets and selectors
- Provides functions for querying facet addresses by selector.
- Enables retrieval of all registered facet addresses and their selectors.
- Includes
exportSelectorsfor mechanism discovery. - Operates on shared diamond storage via
DIAMOND_STORAGE_POSITION.
Overview
This facet provides essential introspection capabilities for diamonds. It exposes functions to query facet addresses, their associated function selectors, and a comprehensive list of all registered facets. Developers integrate this facet to understand the diamond's internal structure and composition programmatically.
Storage
FacetNode
FacetList
DiamondStorage
Facet
State Variables
| Property | Type | Description |
|---|---|---|
DIAMOND_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc8153.diamond")) |
Functions
facetAddress
Gets the facet address that handles the given selector. If facet is not found return address(0).
Parameters:
| Property | Type | Description |
|---|---|---|
_functionSelector | bytes4 | The function selector. |
Returns:
| Property | Type | Description |
|---|---|---|
facet | address | The facet address. |
facetFunctionSelectors
Gets the function selectors that are handled by the given facet. If facet is not found return empty array.
Parameters:
| Property | Type | Description |
|---|---|---|
_facet | address | The facet address. |
Returns:
| Property | Type | Description |
|---|---|---|
facetSelectors | bytes4[] | The function selectors. |
facetAddresses
Gets the facet addresses used by the diamond. If no facets are registered return empty array.
Returns:
| Property | Type | Description |
|---|---|---|
allFacets | address[] | The facet addresses. |
facets
Returns the facet address and function selectors of all facets in the diamond.
Returns:
| Property | Type | Description |
|---|---|---|
facetsAndSelectors | Facet[] | An array of Facet structs containing each facet address and its function selectors. |
exportSelectors
Exports the function selectors of the DiamondInspectFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the DiamondInspectFacet |
Best Practices
- Integrate this facet to enable external inspection of diamond facet mappings.
- Use
facetAddressto determine which facet handles a specific function selector. - Utilize
facetsandfacetFunctionSelectorsfor comprehensive diamond structure analysis.
Security Considerations
All functions in this facet are view or pure, posing no direct reentrancy or state-changing risks. Input validation for facetAddress and facetFunctionSelectors is handled by the diamond proxy's dispatch mechanism. Follow standard Solidity security practices.