Keysets
define-keyset
Use define-keyset
to define a keyset with the specified name
and keyset
guard.
I you don't specify a keyset guard, the functions reads the specified keyset name
from the message payload to define its keyset guard, which is similar to using the read-keyset
function.
If the keyset name
already exists, the existing keyset is enforced before updating to the new value.
Basic syntax
To define a keyset as name
with keyset
, use the following syntax:
(define-keyset name keyset)
(define-keyset name keyset)
To read keyset information from the transaction message payload, use the following syntax:
(define-keyset name)
(define-keyset name)
Arguments
Use the following arguments to specify the inputs for the define-keyset
Pact function:
Argument | Type | Description |
---|---|---|
name | string | Specifies the name of the keyset to define or read. |
keyset | string | Specifies the keyset to associate with the name . |
Return values
The define-keyset
function returns a string representing the result of defining the keyset.
Examples
The following example demonstrates how to use the define-keyset
function to define a keyset named "admin-keyset" to use the keys and predicate function from the specified "my-keyset" object:
(define-keyset 'admin-keyset "my-keyset")
(define-keyset 'admin-keyset "my-keyset")
The following example demonstrates how to read the keyset from the message payload and associate it with admin-keyset
:
(define-keyset 'admin-keyset)
(define-keyset 'admin-keyset)
The following example illustrates how to define a keyset by reading an existing keyset:
(define-keyset "admin-keyset" (read-keyset 'admin-keyset))
(define-keyset "admin-keyset" (read-keyset 'admin-keyset))
enforce-keyset
Use enforce-keyset
to execute a specified guard
or a defined keyset named keysetname
to enforce the desired predicate logic.
Basic syntax
To execute a guard
to enforce desired predicate logic, use the following syntax:
(enforce-keyset guard)
(enforce-keyset guard)
To require a specified keyset to enforce desired predicate logic, use the following syntax:
(enforce-keyset keysetname)
(enforce-keyset keysetname)
Arguments
Use the following arguments to specify the guard
or keysetname
for the enforce-keyset
Pact function:
Argument | Type | Description |
---|---|---|
guard | guard | Specifies the guard to execute. |
keysetname | string | Specifies the name of the defined keyset to enforce. |
Return values
The enforce-keyset
function returns a boolean value indicating whether the specified guard or keyset predicate logic was enforced.
Examples
The following example demonstrates how to use the enforce-keyset
function to enforce logic defined in the "admin-keyset" predicate function:
(enforce-keyset 'admin-keyset)
(enforce-keyset 'admin-keyset)
If the condition specified by the admin-keyset
predicate function is satisfied, the enforce-keyset
function returns a boolean value of true.
The following example enforces the logic defined in the row-guard
predicate logic:
(enforce-keyset row-guard)
(enforce-keyset row-guard)
If the condition specified by the row-guard
predicate function is satisfied, the enforce-keyset
function returns a boolean value of true.
keys-2
Use keys-2
as a keyset predicate function to determine if there are at least two keys that match the keys defined in a keyset.
Basic syntax
To check whether there are at least two keys that match the keys defined in a keyset, use the following syntax:
keys-2 count matched
keys-2 count matched
Arguments
Use the following arguments to specify the count of keys in the keyset and the number of matched keys using the keys-2
Pact function.
Argument | Type | Description |
---|---|---|
count | integer | Specifies the total count of keys defined in the keyset. |
matched | integer | Specifies the number of matched keys. |
Return value
The keys-2
function returns a boolean value indicating whether there are at least two keys that match the keys defined in the keyset.
Examples
The following example demonstrates how to use the keys-2
to check if at least two keys are matched in a keyset where the total number of keys defined in a keyset is three and only one key is matched:
pact> (keys-2 3 1)false
pact> (keys-2 3 1)false
The function returns false because the condition of having at least two keys matched is not met.
keys-all
Use keys-all
as a keyset predicate function to determine if all of the keys defined in the keyset are matched.
Basic syntax
To check whether all of the keys defined in a keyset are matched, use the following syntax:
(keys-all count matched)
(keys-all count matched)
Arguments
Use the following arguments to specify the count of keys in the keyset and the number of matched keys using the keys-all
Pact function.
Argument | Type | Description |
---|---|---|
count | integer | Specifies the total count of keys defined in the keyset. |
matched | integer | Specifies the number of matched keys. |
Return value
The keys-all
function returns a boolean value indicating whether all keys in the keyset are matched.
Examples
The following example demonstrates how to use the keys-all
function to check whether all of the keys are matched in a keyset where the total number of keys defined is three:
pact> (keys-all 3 3)true
pact> (keys-all 3 3)true
The function returns true because all keys in the keyset are matched.
keys
Use keys
to return all keys present in a specified table.
Basic syntax
To retrieve all keys present in a table
, use the following syntax:
(keys table)
(keys table)
Arguments
Use the following argument to specify the table from which you want to retrieve keys using the keys
Pact function.
Argument | Type | Description |
---|---|---|
table | table<{row}> | Specifies the table from which keys will be retrieved. |
Return value
The keys
function returns a list of strings containing all keys present in the specified table.
Examples
The following example demonstrates how to use the keys
function to retrieve all of the keys present in the "accounts" table:
(keys accounts)
(keys accounts)
In this example, all keys present in the "accounts" table are returned as a list of strings.