createRule(Asynchronously creates a new rule in the rules engine policy contract.config,rulesEnginePolicyContract,rulesEngineRulesContract,rulesEngineComponentContract,rulesEngineForeignCallContract,policyId,ruleS,foreignCallNameToID,trackerNameToID):Promise<number>
Parameters
| Parameter | Type | Description |
|---|---|---|
config | Config | - |
rulesEnginePolicyContract | object | - |
rulesEnginePolicyContract.abi | (object | object)[] | - |
rulesEnginePolicyContract.address | `0x${string}` | - |
rulesEngineRulesContract | object | The contract instance for interacting with the rules engine policy. |
rulesEngineRulesContract.abi | (object | object | object)[] | - |
rulesEngineRulesContract.address | `0x${string}` | - |
rulesEngineComponentContract | object | - |
rulesEngineComponentContract.abi | (object | object | object)[] | - |
rulesEngineComponentContract.address | `0x${string}` | - |
rulesEngineForeignCallContract | object | - |
rulesEngineForeignCallContract.abi | (object | object | object)[] | - |
rulesEngineForeignCallContract.address | `0x${string}` | - |
policyId | number | The ID of the policy to which the rule belongs. |
ruleS | string | A JSON string representing the rule to be created. |
foreignCallNameToID | FCNameToID[] | An array mapping foreign call names to their corresponding IDs. |
trackerNameToID | FCNameToID[] | An array mapping tracker names to their corresponding IDs. |
Returns
Promise<number>
A promise that resolves to the result of the rule creation operation. Returns the rule ID if successful, or -1 if the operation fails.
Throws
Will log errors to the console if the contract simulation fails and retry the operation after a delay.Remarks
- The function parses the rule JSON string to build the rule and effect structures.
- It uses a retry mechanism with a delay to handle potential failures during contract simulation.
- If the rule creation is successful, it writes the contract, generates a rule modifier, and optionally injects the modifier into the specified contract.