RulesEngine
Constructors
new RulesEngine()
new RulesEngine(
rulesEngineAddress
,localConfig
,client
):RulesEngine
Parameters
Parameter | Type | Description |
---|---|---|
rulesEngineAddress | `0x${string}` | The address of the deployed Rules Engine smart contract. |
localConfig | Config | - |
client | any | The client instance for interacting with the blockchain. |
Returns
Defined in
src/modules/rules-engine.ts:74
Methods
applyPolicy()
applyPolicy(
policyId
,contractAddressForPolicy
):Promise
<number
>
Applies a policy to a specific contract address.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to apply. |
contractAddressForPolicy | `0x${string}` | The address of the contract to which the policy will be applied. |
Returns
Promise
<number
>
The result of the policy application.
Defined in
src/modules/rules-engine.ts:137
createForeignCall()
createForeignCall(
policyId
,fcSyntax
):Promise
<number
>
Creates a foreign call in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to associate with the foreign call. |
fcSyntax | string | A JSON string representing the foreign call definition. |
Returns
Promise
<number
>
A promise that resolves to the foreign call index. Returns -1
if the operation fails.
Remarks
- The function retries the contract interaction in case of failure, with a delay of 1 second between attempts.
- The
simulateContract
function is used to simulate the contract interaction before writing to the blockchain. - The
writeContract
function is used to execute the contract interaction on the blockchain. - The function returns the
foreignCallIndex
for an updated foreign call or the result of the newly created foreign call.
Throws
Will throw an error if the JSON parsing of fcSyntax
fails.
Defined in
src/modules/rules-engine.ts:258
createFunctionSignature()
createFunctionSignature(
policyId
,functionSignature
):Promise
<number
>
Creates a function signature in the rules engine component contract.
This function parses the provided function signature, maps its arguments to their respective types, and interacts with the smart contract to create the function signature. If the contract interaction fails, it retries with a delay until successful.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy for which the function signature is being created. |
functionSignature | string | The function signature string to be parsed and added to the contract. |
Returns
Promise
<number
>
A promise that resolves to the result of the contract interaction, or -1 if unsuccessful.
Throws
Will retry indefinitely on contract interaction failure, with a delay between attempts.
Defined in
src/modules/rules-engine.ts:415
createNewRule()
createNewRule(
policyId
,ruleS
,foreignCallNameToID
,trackerNameToID
):Promise
<number
>
Asynchronously creates a new rule in the rules engine policy contract.
Parameters
Parameter | Type | Description |
---|---|---|
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.
Defined in
src/modules/rules-engine.ts:180
createPolicy()
createPolicy(
policyJSON
):Promise
<object
>
Creates a policy in the Rules Engine.
Parameters
Parameter | Type | Description |
---|---|---|
policyJSON | string | Policy defined in a JSON string. |
Returns
Promise
<object
>
The ID of the newly created policy.
functionSignatureMappings
functionSignatureMappings:
hexToFunctionSignature
[]
policyId
policyId:
number
Defined in
src/modules/rules-engine.ts:100
createTracker()
createTracker(
policyId
,trSyntax
):Promise
<number
>
Asynchronously creates a tracker in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy associated with the tracker. |
trSyntax | string | A JSON string representing the tracker syntax. |
Returns
Promise
<number
>
A promise that resolves to the new tracker ID
Throws
Will retry indefinitely with a 1-second delay between attempts if an error occurs during the contract simulation. Ensure proper error handling or timeout mechanisms are implemented to avoid infinite loops.
Defined in
src/modules/rules-engine.ts:337
deleteForeignCall()
deleteForeignCall(
policyId
,foreignCallId
):Promise
<number
>
Deletes a foreign call associated with a specific policy in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to which the foreign call belongs. |
foreignCallId | number | The ID of the foreign call to be deleted. |
Returns
Promise
<number
>
A promise that resolves to a number:
0
if the operation is successful.-1
if an error occurs during the simulation of the contract interaction.
Throws
This function does not explicitly throw errors but will return -1
if an error occurs during the simulation phase.
Defined in
src/modules/rules-engine.ts:295
deletePolicy()
deletePolicy(
policyId
):Promise
<number
>
Deletes a policy from the Rules Engine.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to delete. |
Returns
Promise
<number
>
0
if successful, -1
if an error occurs.
Defined in
src/modules/rules-engine.ts:148
deleteRule()
deleteRule(
policyId
,ruleId
):Promise
<number
>
Deletes a rule from the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to which the rule belongs. |
ruleId | number | The ID of the rule to be deleted. |
Returns
Promise
<number
>
A promise that resolves to a number:
0
if the rule was successfully deleted.-1
if an error occurred during the deletion process.
Throws
This function does not throw errors directly but returns -1
in case of an exception.
Defined in
src/modules/rules-engine.ts:213
deleteTracker()
deleteTracker(
policyId
,trackerId
):Promise
<number
>
Deletes a tracker associated with a specific policy in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to which the tracker belongs. |
trackerId | number | The ID of the tracker to be deleted. |
Returns
Promise
<number
>
A promise that resolves to a number:
0
if the tracker was successfully deleted.-1
if an error occurred during the simulation of the contract interaction.
Throws
This function does not explicitly throw errors but will return -1
if an error occurs during the simulation phase.
Defined in
src/modules/rules-engine.ts:369
getAllForeignCalls()
getAllForeignCalls(
policyId
):Promise
<null
|any
[]>
Retrieves all foreign calls associated with a specific policy ID from the Rules Engine Component Contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy for which foreign calls are to be retrieved. |
Returns
Promise
<null
| any
[]>
A promise that resolves to an array of foreign calls if successful, or null
if an error occurs.
Throws
Will log an error to the console if the operation fails.
Defined in
src/modules/rules-engine.ts:322
getAllRules()
getAllRules(
policyId
):Promise
<null
|any
[]>
Retrieves all rules associated with a specific policy ID from the Rules Engine Policy Contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The unique identifier of the policy for which rules are to be retrieved. |
Returns
Promise
<null
| any
[]>
A promise that resolves to an array of rules if successful, or null
if an error occurs.
Throws
Will log an error to the console if the operation fails.
Defined in
src/modules/rules-engine.ts:238
getAllTrackers()
getAllTrackers(
policyId
):Promise
<null
|any
[]>
Retrieves all trackers associated with a specific policy ID from the Rules Engine Component Contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The unique identifier of the policy for which trackers are to be retrieved. including its address and ABI. |
Returns
Promise
<null
| any
[]>
A promise that resolves to an array of trackers if successful, or null
if an error occurs.
Throws
Will log an error to the console if the operation fails.
Defined in
src/modules/rules-engine.ts:397
getForeignCall()
getForeignCall(
policyId
,foreignCallId
):Promise
<any
>
Retrieves the result of a foreign call from the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy associated with the foreign call. |
foreignCallId | number | The ID of the foreign call to retrieve. |
Returns
Promise
<any
>
A promise that resolves to the result of the foreign call, or null
if an error occurs.
Throws
Will log an error to the console if the contract interaction fails.
Defined in
src/modules/rules-engine.ts:309
getPolicy()
getPolicy(
policyId
,functionSignatureMappings
):Promise
<string
>
Retrieves the full policy, including rules, trackers, and foreign calls, as a JSON string.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to retrieve. |
functionSignatureMappings | hexToFunctionSignature [] | A mapping of function signatures to their hex representations. |
Returns
Promise
<string
>
A JSON string representing the full policy.
Defined in
src/modules/rules-engine.ts:160
getRule()
getRule(
policyId
,ruleId
):Promise
<null
|RuleStruct
>
Retrieves a specific rule from the Rules Engine.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy containing the rule. |
ruleId | number | The ID of the rule to retrieve. |
Returns
Promise
<null
| RuleStruct
>
The retrieved rule as a RuleStruct
, or null
if retrieval fails.
Defined in
src/modules/rules-engine.ts:225
getRulesEngineComponentContract()
getRulesEngineComponentContract():
object
Returns
object
abi
abi: (
object
|object
|object
)[]
address
address: `0x${string}`
Defined in
src/modules/rules-engine.ts:90
getRulesEnginePolicyContract()
getRulesEnginePolicyContract():
object
Returns
object
abi
abi: (
object
|object
|object
)[]
address
address: `0x${string}`
Defined in
src/modules/rules-engine.ts:87
getTracker()
getTracker(
policyId
,trackerId
):Promise
<any
>
Retrieves a tracker from the Rules Engine Component Contract based on the provided policy ID and tracker ID.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy associated with the tracker. |
trackerId | number | The ID of the tracker to retrieve. |
Returns
Promise
<any
>
A promise that resolves to the tracker result if successful, or null
if an error occurs.
Throws
Will log an error to the console if the contract interaction fails.
Defined in
src/modules/rules-engine.ts:383
policyExists()
policyExists(
policyId
):Promise
<boolean
>
Checks if a policy exists in the Rules Engine.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to check. |
Returns
Promise
<boolean
>
True if the policy exists, false otherwise.
Defined in
src/modules/rules-engine.ts:111
updateForeignCall()
updateForeignCall(
policyId
,foreignCallId
,fcSyntax
):Promise
<number
>
Updates a foreign call in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to associate with the foreign call. |
foreignCallId | number | The ID of the foreign call to update. |
fcSyntax | string | A JSON string representing the foreign call definition. |
Returns
Promise
<number
>
A promise that resolves to the foreign call index. Returns -1
if the operation fails.
Remarks
- The function retries the contract interaction in case of failure, with a delay of 1 second between attempts.
- The
simulateContract
function is used to simulate the contract interaction before writing to the blockchain. - The
writeContract
function is used to execute the contract interaction on the blockchain. - The function returns the
foreignCallIndex
for an updated foreign call or the result of the newly created foreign call.
Throws
Will throw an error if the JSON parsing of fcSyntax
fails.
Defined in
src/modules/rules-engine.ts:279
updatePolicy()
updatePolicy(
policyId
,signatures
,ids
,ruleIds
):Promise
<number
>
Updates an existing policy in the Rules Engine.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to update. |
signatures | any [] | The function signatures associated with the policy. |
ids | number [] | The IDs of the rules associated with the policy. |
ruleIds | any [] | The mapping of rules to function signatures. |
Returns
Promise
<number
>
The result of the policy update.
Defined in
src/modules/rules-engine.ts:125
updateRule()
updateRule(
policyId
,ruleId
,ruleS
,foreignCallNameToID
,trackerNameToID
):Promise
<number
>
Updates an existing rule in the Rules Engine Policy Contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy to which the rule belongs. |
ruleId | number | The ID of the rule to be updated. |
ruleS | string | A JSON string representing the rule’s structure and logic. |
foreignCallNameToID | FCNameToID [] | A mapping of foreign call names to their corresponding IDs. |
trackerNameToID | FCNameToID [] | A mapping of tracker names to their corresponding IDs. |
Returns
Promise
<number
>
A promise that resolves to the result of the rule update operation. Returns the result ID if successful, or -1 if the operation fails.
Throws
Will retry indefinitely if the contract simulation fails, with a 1-second delay between retries.
Defined in
src/modules/rules-engine.ts:197
updateTracker()
updateTracker(
policyId
,trackerId
,trSyntax
):Promise
<number
>
Asynchronously updates a tracker in the rules engine component contract.
Parameters
Parameter | Type | Description |
---|---|---|
policyId | number | The ID of the policy associated with the tracker. |
trackerId | number | The ID of the tracker to update. |
trSyntax | string | A JSON string representing the tracker syntax. |
Returns
Promise
<number
>
A promise that resolves to the existing tracker ID is returned. Returns -1 if the operation fails.
Throws
Will retry indefinitely with a 1-second delay between attempts if an error occurs during the contract simulation. Ensure proper error handling or timeout mechanisms are implemented to avoid infinite loops.