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:

  1. Adds an import statement for RulesEngineClientCustom after the pragma line.
  2. Updates the contract declaration to inherit from RulesEngineClientCustom.
  3. Adds a checkRulesBefore modifier to the specified function with the provided arguments.
  4. Writes the modified content back to the file and generates a diff file showing the changes.

Parameters

ParameterTypeDescription
funcNamestringThe name of the function to which the modifier will be added.
variablesstringA comma-separated string of variables to be passed to the modifier. Supported types include address, uint256, string, bool, and bytes.
userFilePathstringThe file path of the Solidity contract to be modified.
diffPathstringThe file path where the diff of the changes will be saved.
modifierFilestring-

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.

Defined in

src/codeGeneration/inject-modifier.ts:65