đRequestBuilder
The RequestBuilder
library in Solidity is designed to help users create and manage complex request operations. It uses a structured approach to manage operations and their operands, which may be encrypted values or indices pointing to previously computed results. This guide provides a detailed explanation of the structure and usage of the RequestBuilder
library.
Structure
The library contains two primary structures:
Operation
Request
Operation Structure
The Operation
structure represents an individual operation with the following fields:
opcode
: Auint8
representing the operation code, which defines the type of operation.operands
: Auint256[]
array representing the indices of operands or an encrypted value.value
: Auint64
representing a direct value if applicable.
Request Structure
The Request
structure aggregates multiple operations and manages their execution. It includes:
id
: A unique identifier for the request, generated upon completion.requester
: The address of the entity making the request.ops
: An array ofOperation
structures.opsCursor
: A cursor to track the current position in theops
array.callbackAddr
: Address for the callback once the request is processed.callbackFunc
: Function signature for the callback.payload
: Additional data to be sent with the request.
Usage of Operands as Indices
In this library, operands are used as indices rather than direct values. This approach allows for flexible and efficient referencing of previously computed results within the same request. Each operation can reference the result of another operation by its index in the ops
array. This method enhances modularity and composability in constructing complex operations.
Example
To add two encrypted uint64 values and store the result:
Load the first encrypted value:
Load the second encrypted value:
Add the two values and store the result:
Last updated