createRule
createRule(
config
,rulesEnginePolicyContract
,policyId
,ruleS
,foreignCallNameToID
,trackerNameToID
):Promise
<number
>
Asynchronously creates a new rule in the rules engine policy contract.
Parameters
Parameter | Type | Description |
---|---|---|
config | Config | - |
rulesEnginePolicyContract | object | The contract instance for interacting with the rules engine policy. |
rulesEnginePolicyContract.abi | (object | object | object )[] | - |
rulesEnginePolicyContract.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.