Git Source

Author: @oscarsernarosero, built on top of Nick Mudge implementation.

Contract serves as library for the Processor Diamond

Library contract of the diamond pattern. Responsible for checking on rules compliance.

State Variables

DIAMOND_CUT_STORAGE

bytes32 constant DIAMOND_CUT_STORAGE = bytes32(uint256(keccak256("diamond-cut.storage")) - 1);

RULE_DATA_POSITION

bytes32 constant RULE_DATA_POSITION = keccak256("nontagged-ruless.rule-data.storage");

Functions

s

Function for position of facets and their selectors. Every facet has its own storage.

function s() internal pure returns (RuleProcessorDiamondStorage storage ds);

Returns

NameTypeDescription
dsRuleProcessorDiamondStorageData storage for Rule Processor Facet Storage

ruleDataStorage

Function to store rules

function ruleDataStorage() internal pure returns (RuleDataStorage storage ds);

Returns

NameTypeDescription
dsRuleDataStorageData Storage of Rule Data Storage

diamondCut

Internal function version of _diamondCut

function diamondCut(FacetCut[] memory _diamondCut, address init, bytes memory data) internal;

Parameters

NameTypeDescription
_diamondCutFacetCut[]Facets Array
initaddressAddress of the contract or facet to execute “data”
databytesA function call, including function selector and arguments calldata is executed with delegatecall on “init”

addFunctions

Add Function to Diamond

function addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal;

Parameters

NameTypeDescription
_facetAddressaddressAddress of Facet
_functionSelectorsbytes4[]Signature array of function selectors

replaceFunctions

Replace Function from Diamond

function replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal;

Parameters

NameTypeDescription
_facetAddressaddressAddress of Facet
_functionSelectorsbytes4[]Signature array of function selectors

removeFunctions

can’t replace immutable functions — functions defined directly in the diamond in this case replace old facet address

Remove Function from Diamond

function removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal;

Parameters

NameTypeDescription
_facetAddressaddressAddress of Facet
_functionSelectorsbytes4[]Signature array of function selectors

initializeDiamondCut

can’t remove immutable functions — functions defined directly in the diamond replace selector with last selector delete last selector

Initialize Diamond Cut of new Facet

function initializeDiamondCut(address init, bytes memory data) internal;

Parameters

NameTypeDescription
initaddressThe address of the contract or facet to execute “data”
databytesA function call, including function selector and arguments calldata is executed with delegatecall on “init”

enforceHasContractCode

Internal function to enforce contract has code

function enforceHasContractCode(address _contract, string memory _errorMessage) internal view;

Parameters

NameTypeDescription
_contractaddressThe address of the contract be checked or enforced
_errorMessagestringError for contract with non matching co

Events

DiamondCut

event DiamondCut(FacetCut[] _diamondCut, address init, bytes data);