OVMGateway

Git Source

Inherits: IOVMGateway

THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY. THIS EXAMPLE USES UN-AUDITED CODE. DO NOT USE THIS CODE IN PRODUCTION.

State Variables

EXPIRYTIME

The time after which a request can be canceled

uint256 public constant EXPIRYTIME = 5 minutes;

_requestCount

uint256 internal _requestCount;

_commitments

a commitment is a request that has not been fulfilled yet

mapping(bytes32 requestId => Commitment commitment) internal _commitments;

_tokensInEscrow

Tokens sent for requests that have not been fulfilled yet

uint256 internal _tokensInEscrow;

Functions

sendRequest

Sends a request to execute a task.

function sendRequest(
    address requester,
    address callbackAddress,
    bool deterministic,
    bytes calldata data
) external payable override returns (bytes32 requestId);

Parameters

NameTypeDescription
requesteraddressThe address of the requester.
callbackAddressaddressThe address of the contract to receive the callback.
deterministicboolWhether the request is deterministic.
databytesThe data to be passed to the callback function. msg.value is the payment for the task.

Returns

NameTypeDescription
requestIdbytes32The unique identifier for the request.

cancelRequest

Cancels a request.

function cancelRequest(bytes32 requestId) external override;

Parameters

NameTypeDescription
requestIdbytes32The request ID to cancel.

setResponse

Sets the response for a given requestId.

function setResponse(
    bytes32 requestId,
    bytes calldata data,
    string calldata envProof,
    string calldata inputProof,
    string calldata outputProof,
    string calldata rootProof
) external override;

Parameters

NameTypeDescription
requestIdbytes32The unique identifier for the request.
databytesThe response data to be set.
envProofstringThe environment proof to be set.
inputProofstringThe input proof to be set.
outputProofstringThe output proof to be set.
rootProofstringThe root proof to be set.

getSpecification

Gets the specification of the callback contract.

function getSpecification(address callbackAddress)
    external
    view
    override
    returns (Specification memory);

Parameters

NameTypeDescription
callbackAddressaddressThe address of the callback contract.

Returns

NameTypeDescription
<none>Specificationspecification The specification of the callback contract.

getCommitments

Gets the commitments of a request.

function getCommitments(bytes32 requestId) external view override returns (Commitment memory);

Parameters

NameTypeDescription
requestIdbytes32The request ID to get the commitments for.

Returns

NameTypeDescription
<none>Commitmentcommitments The commitments of the request.

getRequestsCount

Gets the number of requests.

function getRequestsCount() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256count The number of requests.

_transfer

transfer native tokens by a low-level call. _transfer should always be at the end of the function, to apply the checks-effects-interactions pattern

function _transfer(address to, uint256 amount) internal;