injectModifier(Defined in: src/codeGeneration/inject-modifier.ts:88 Injects a modifier into a Solidity contract file by modifying its content. This function performs the following operations:funcName,variables,userFilePath,diffPath,modifierFile):void
- Adds an import statement for
RulesEngineClientCustomafter the pragma line. - Updates the contract declaration to inherit from
RulesEngineClientCustom. - Adds a
checkRulesBeforemodifier 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
checkRulesBeforemodifier is added to the calling function 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 atuserFilePath cannot be read or written.