Functions
injectModifier
injectModifier(
funcName
,variables
,userFilePath
,diffPath
,modifierFile
):void
Injects a modifier into a Solidity contract file by modifying its content.
This function performs the following operations:
- Adds an import statement for
RulesEngineClientCustom
after the pragma line. - Updates the contract declaration to inherit from
RulesEngineClientCustom
. - Adds a
checkRulesBefore
modifier to the specified function with the provided arguments. - Writes the modified content back to the file and generates a diff file showing the changes.
Parameters
Parameter | Type | Description |
---|---|---|
funcName | string | The name of the function to which the modifier will be added. |
variables | string | A comma-separated string of variables to be passed to the modifier. Supported types include address , uint256 , string , bool , and bytes . |
userFilePath | string | The file path of the Solidity contract to be modified. |
diffPath | string | The file path where the diff of the changes will be saved. |
modifierFile | string | - |
Returns
void
Remarks
- The function assumes the Solidity file uses standard formatting for pragma, contract declaration, and function definitions.
- The
checkRulesBefore
modifier is added to the function signature with the provided arguments. - The diff file is generated in a format that highlights added and removed lines.
Throws
Will throw an error if the file at userFilePath
cannot be read or written.
Throws
Will throw an error if the provided function name or variables are invalid.