Module-level declarations
Types
A cursor that points to where pages should start in paginated queries.
The return type of all paginated queries. It contains a list of results of the query, and a cursor which can be used to retrieve the next page.
In general, when a paginated query looks like this: get_my_data(page_size: integer?, page_cursor: text?)
page_size
determines the number of results to be returned, defaulting toquery_max_page_size
as defined in the module args if null or higher than that value.page_cursor
determines where the results should start from, defaulting to the first page.
The returned results will be a paged result with:
data
: a list of the expected data, encoded as GTVsnext_cursor
: a base64 encodedpage_cursor
that can be passed aspage_cursor
to the same query to retrieve the next page of data
The cursors are not supposed to be interpreted in any way on the front-end. To avoid unexpected behavior, only pass cursors received from a query to that same query.
An element of a page that should be returned by paginated queries.
For complex validation we might not want to use simple "require()" but an error message that is returned.
Properties
Functions
Returns the rowid of the last retrieved element, given the base64-encoded page_cursor
.
Useful to retrieve the rowid where the last query stopped, to start retrieving a new page from there.
Converts a gtv value to a pretty text representation, with newlines and indentations. Used to create pretty auth messages which include all parameters passed to a certain operation, regardless of complexity.
It's still recommended to create custom auth messages for complex operations, as they will always be more readable than any automatically generated text.
Decodes a page_cursor
from a base64 string, received as a query parameter.
A utility function that computes a unique nonce for this operation's message to sign.
Encodes a page_cursor
into a base64 string to make it more manageable for the frontend
Used to calculate the page size for the current query. The value will be:
query_max_page_size
ifpage_size
is null or higher than that valuepage_size
otherwise
A validation_result
to be returned when an error should be thrown
Used to check if a gtv value is encoding a big_integer
Used to check if a gtv value is encoding a byte_array
Used to check if a gtv value is encoding an integer
Returns the last block time regardless of whether op_context
exists. Returns 0 if this is the first block.
A utility function that adds a header and a footer to every auth message.
The header contains the blockchain RID to avoid the same signature to be maliciously used on other chains in a cross-chain replay attack.
The footer contains a nonce to avoid the same signature to be maliciously used on this same chain in a classic replay attack.
Creates a page from a list of pagination_result
s and the expected size of the page. It will never return pages bigger than query_max_page_size
.
Used by paginated queries to build the actual paged_result
that will be returned.
Throws "PAGE SIZE TOO SMALL"
if page_size
is less than 1
Utility function that returns an empty page with no next page
Checks whether the blockchain RID has the correct size
Throws "INVALID BRID"
if the RID's length is not 32 bytes.
Should be used inside other functions, and the descriptor
parameter should be passed in a way that the error message is understood by the end users.
Example: validate_blockchain_rid(x"", "Chain X's RID")
will throw this error: "INVALID BRID: Chain X's RID cannot be empty"